ios - 在 iOS 8 中显示 UIAlertView 时应用程序旋转

标签 ios iphone uiviewcontroller ios8 uialertview

我正在开发一款主要用于纵向模式的应用(少数 View 除外)。 我们在 iOS 8 中遇到了一个问题,即在显示 UIViewAlert 时应用程序能够旋转,即使底层 View Controller 仅支持纵向方向并且其 shouldAutorotate 方法返回不。当 UIAlertView 旋转到横向时,旋转甚至还没有完全旋转,但底层 View 仍处于纵向模式。如果我们在 iOS 7 中运行该应用程序,则没有问题。

我知道 UIAlertView 已在 iOS 8 中弃用,我们现在应该使用 UIAlertController。但是,我真的很想避免替换它,因为这意味着要编辑 50 多个使用 UIAlertViewUIAlertViewDelegate 的类。此外,我们仍然支持 iOS 7,所以我必须同时拥有这两种解决方案。当我们完全切换到 iOS 8 时,我宁愿只需要执行一次。

最佳答案

只需将其放入您的UIApplicationDelegate 实现

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

关于ios - 在 iOS 8 中显示 UIAlertView 时应用程序旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28699275/

相关文章:

iphone - 从 iphone 中的 .wav 文件读取时数据为空?

iphone - 通过在iphone sdk中解析获取城市名称

javascript - Appcelerator 应用程序计时器,用于检查服务器 api 响应

ios - 如何在 iOS 中显示来自 IP Camera/CCTV 的 RTSP

ios - 越狱的 iOS 设备在使用 HTTPS 时是否可以访问 NSURLConnection 数据?

ios - 使用 SW Reveal Controller 设置自定义转场

ios - 如何在 Cocos2d V3 中模态或呈现 viewController?

ios - 如果我上传新版本的应用程序,TestFlight 会删除我以前的版本吗?

c# - MonoTouch - 重用 UIAlertVIew?

ios - 如何 'cancel' 查看自定义容器 Controller 转换的外观转换