Ash*_*iya 39 objective-c uialertcontroller ios9 xcode7 xcode7-beta3
当两个警报一个接一个地呈现时,我意味着一个警报存在,并且在他们上面另一个警报呈现和应用程序崩溃.我曾经用来UIAlertController显示警报.应用程序仅在iOS 9设备中崩溃.
请帮助我.
小智 75
这是iOS 9中的一个错误,它无法检索supportedInterfaceOrientationsfor UIAlertController.它似乎下降到一个无限递归循环中寻找supportedInterfaceOrientations的UIAlertController(例如,它跟踪回UIAlertControler- > UIViewController- > UINavigationController- > UITabBarController- > UIAlertController- > ...),而到了呼叫UIAlertController:supportedInterfaceOrientations实际未实现/重写源码.
在我的解决方案中,我刚刚添加了以下代码:
extension UIAlertController {
public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.Portrait
}
public override func shouldAutorotate() -> Bool {
return false
}
}
Run Code Online (Sandbox Code Playgroud)
然后UIAlertController将直接返回支持的方向值而无需无限循环.希望能帮助到你.
编辑:Swift 3.0.1
extension UIAlertController {
open override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait
}
open override var shouldAutorotate: Bool {
return false
}
}
Run Code Online (Sandbox Code Playgroud)
Jim*_*and 16
我的解决方案是UIAlertViewController的Objective-C类别.只需在使用UIAlertController的任何类中包含UIAlertController + supportedInterfaceOrientations.h即可
UIAlertController + supportedInterfaceOrientations.h
//
// UIAlertController+supportedInterfaceOrientations.h
#import <UIKit/UIKit.h>
@interface UIAlertController (supportedInterfaceOrientations)
@end
Run Code Online (Sandbox Code Playgroud)
UIAlertController + supportedInterfaceOrientations.m
//
// UIAlertController+supportedInterfaceOrientations.m
#import "UIAlertController+supportedInterfaceOrientations.h"
@implementation UIAlertController (supportedInterfaceOrientations)
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
#endif
@end
Run Code Online (Sandbox Code Playgroud)
作为Roland Keesom回答的更新,上面的内容对我有用.主要区别在于supportedInterfaceOrientations函数实际上返回的是UIInterfaceOrientationMask而不是Int.
在此变体中,支持所有方向.
extension UIAlertController {
public override func shouldAutorotate() -> Bool {
return true
}
public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.All
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8407 次 |
| 最近记录: |