I am working on an app that is mostly used in portrait mode (except for a few views).
We are encountering an issue in iOS 8 where the app is able to rotate when an UIViewAlert
is shown, even though the underlaying view controller only supports portrait orientation and its shouldAutorotate
method returns NO. The rotation is not even full as the UIAlertView
rotates to landscape, but the underlying view remains in portrait mode. There is no problem if we run the app in iOS 7.
I know that UIAlertView
has been deprecated in iOS 8 and that we should now use UIAlertController
. However, I would really like to avoid having to replace it as this would mean editing 50+ classes that use UIAlertView
and UIAlertViewDelegate
. Also, we still support iOS 7 so I would have to have both solutions. I would prefer only to have to do this once, when we make the full switch to iOS 8.
Swipe down from the top-right corner of your screen to open Control Center. Tap the Portrait Orientation Lock button to make sure that it's off.
Make sure that Rotation Lock is off: Swipe down from the top-right corner of your screen to open Control Center. Then tap the Rotation Lock button to make sure it's off. Turn your iPad sideways.
Android Settings Start by going to Settings => Display and locate the “Device rotation” setting.
Just put this in your UIApplicationDelegate
implementation
Swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
if window == self.window {
return Int(UIInterfaceOrientationMask.All.rawValue) // Mask for all supported orientations in your app
} else {
return Int(UIInterfaceOrientationMask.Portrait.rawValue) // Supported orientations for any other window (like one created for UIAlert in iOS 8)
}
}
}
Objective-C
@implementation AppDelegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (window == self.window) {
return UIInterfaceOrientationMaskAll; // Mask for all supported orientations in your app
} else {
return UIInterfaceOrientationMaskPortrait; // Supported orientations for any other window (like one created for UIAlert in iOS 8)
}
}
@end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With