Assumptions:
- You're using
UIPageViewControllerfor onboarding - You have an
UIViewControllerwith a container that embeds theUIPageViewController - You present this
UIViewControllermodally
The UIViewController container lets you do two things:
- Add a close button that's always visible, and doesn't scroll with the
UIPageViewController - Prevent rotation to landscape
- Rotate to portrait if the user was already in landscape to begin with
// UIViewController
override func viewWillAppear(animated: Bool) {
if UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation) {
let value = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}
}
override func shouldAutorotate() -> Bool {
return !UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation)
}