作者:神奇伟哥 | 来源:互联网 | 2023-05-20 16:26
我正在开发一个主要用于纵向模式的应用程序(除少数视图外).我们在iOS 8中遇到一个问题UIViewAlert
,即使底层视图控制器仅支持纵向方向且其shouldAutorotate
方法返回NO ,应用程序在显示时也能够旋转.UIAlertView
旋转到横向时旋转甚至不完整,但底层视图仍保持纵向模式.如果我们在iOS 7中运行应用程序没有问题.
我知道UIAlertView
iOS 8已被弃用,我们现在应该使用它UIAlertController
.但是,我真的希望避免更换它,因为这意味着要编辑50多个使用UIAlertView
和的类UIAlertViewDelegate
.此外,我们仍然支持iOS 7,所以我必须有两个解决方案.当我们完全切换到iOS 8时,我宁愿只做一次.
1> Silmaril..:
把它放在你的UIApplicationDelegate
实现中
迅速
@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