ios8 - 当屏幕处于横向模式时,UIAlertview 以纵向模式显示

标签 ios8 orientation alertview

我有一个配置为仅支持纵向模式的应用程序。但是我必须以横向模式在我的应用程序中显示一个屏幕(比如 abcViewController)。当 abcViewController 屏幕被按下时,方向从纵向模式变为横向模式。在那个 abcViewController 屏幕状态栏中,所有图像、按钮都以横向模式显示,但 UIAlertView 以纵向模式显示。
这意味着在 abcViewController 中 View 上的所有内容都更改为横向模式,但 UIAlertView 不会旋转到横向模式并保持纵向模式。
我希望 UIAlertView 遵循包含 View Controller 的规则并显示与 statusBar 相同的方向。

enter image description here

注意:我正在使用 Xcode 5.0 在 iOS 8.0 上运行我的应用程序,我正在寻找支持 Xcode 5.0 的解决方案

最佳答案

其实我转了UIView和这个类的状态栏以编程方式用于 iOS 7 和更早的 iOS 版本,但我在 iOS 8 中遇到了这个方向问题,然后我阅读了 iOS 8 的一个新的变化,它与方向相关,如下所示:

我在 iOS 7 和 iOS 8 中运行了以下代码:

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
BOOL landscape = (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight);
NSLog(@"Currently landscape: %@, width: %.2f, height: %.2f", 
      (landscape ? @"Yes" : @"No"), 
      [[UIScreen mainScreen] bounds].size.width, 
      [[UIScreen mainScreen] bounds].size.height);

以下是来自 iOS 8 的结果:
Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 568.00, height: 320.00

与 iOS 7 中的结果相比:
Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 320.00, height: 568.00

所以,我知道 [UIScreen mainScreen].bounds.size 在 iOS8 中变得依赖于方向。

在阅读了 iOS 8 的这个新变化后,我为 iOS 8 创建了一个新类,所以你有两个解决这个问题的方法。

解决方案 1:您应该使用 UIAlertController而不是 UIAlertView .

解决方案 2:您可以为您面临此方向问题的 iOS 8 创建一个新类。

关于ios8 - 当屏幕处于横向模式时,UIAlertview 以纵向模式显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27010160/

相关文章:

ios5 - iOS 5 : willRotateToInterfaceOrientation:duration not called when first loading controller

ios - 如何在UIAlertView的中心添加UIActivityIndi​​catorView?

ios - 如何在 ios 中检测系统弹出 View 的 "Cancel"按钮?

ios - 升级到最新的 XCode beta 3 后 Swift 应用程序崩溃

ios - 检测 iOS 8 quicktype 键盘在没有通知的情况下打开或关闭

ios - 如何使用swift在sprite kit中旋转sprite

iOS:即使使用 shouldAutorotateToInterfaceOrientation 也不会调用 willAnimateRotationToInterfaceOrientation

ios - 如何使用 UINavigationController 强制设置横向方向(Swift 2.0 iOS 9)

ios - 创建一个包含 UIAlertView、UIActivityIndi​​cator 等函数的类,并在各种 viewController 中回调它们

ios - UIScrollView 编程滚动不起作用 iOs 8