Assumptions:
- You're using
UIPageViewController
for onboarding - You have an
UIViewController
with a container that embeds theUIPageViewController
- You present this
UIViewController
modally
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)
}