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