paj*_*vic 4 iphone uiviewcontroller uialertview ios ios8
我正在开发一个主要用于纵向模式的应用程序(除少数视图外).我们在iOS 8中遇到一个问题UIViewAlert,即使底层视图控制器仅支持纵向方向且其shouldAutorotate方法返回NO ,应用程序在显示时也能够旋转.UIAlertView旋转到横向时旋转甚至不完整,但底层视图仍保持纵向模式.如果我们在iOS 7中运行应用程序没有问题.
我知道UIAlertViewiOS 8已被弃用,我们现在应该使用它UIAlertController.但是,我真的希望避免更换它,因为这意味着要编辑50多个使用UIAlertView和的类UIAlertViewDelegate.此外,我们仍然支持iOS 7,所以我必须有两个解决方案.当我们完全切换到iOS 8时,我宁愿只做一次.
把它放在你的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)
}
}
}
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2406 次 |
| 最近记录: |