[英]Crash on shouldAutorotate() method when UIAlertview show in Landscape viewcontroller?
I am working on a app in which I am using only one orientation which is Portrait. 我正在开发一个仅使用一个方向(即人像)的应用程序。 This is device orientation setting: 这是设备方向设置:
But In my app there is Video player (Custom Player of MPMoviePlayerViewController
) which I wanted to show in Landscape Right mode only and It should not be rotated. 但是在我的应用程序中,我只想在“横向右”模式下显示视频播放器( MPMoviePlayerViewController
自定义播放器),并且不应旋转它。 This is working fine, I mean this Custom Player is showing in Landscape Right perfectly, but when I am using an UIAlertview
then application is crashed on this method: 一切正常,我的意思是该自定义播放器在“横向右移”中完美显示,但是当我使用UIAlertview
应用程序在此方法上崩溃了:
- (BOOL)shouldAutorotate {
return NO;
}
These are some other orientation methods : 这些是其他一些定向方法:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeRight; // or Right of course
}
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)supportedInterfaceOrientations
#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif
{
return UIInterfaceOrientationMaskLandscape;
}
I am getting this Error: 我收到此错误:
*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [UIAlertController shouldAutorotate] is returning YES'
iOS8 :UIAlertController iOS8:UIAlertController
#import "UIAlertController+Portrait.h"
@implementation UIAlertController (Portrait)
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
@end
iHTCboy's answer fixed it for me after converting to swift. iHTCboy的答案在转换为swift后为我解决了。
In swift 4: 快速4:
extension UIAlertController {
override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .all }
}
Solution 1. Go to info.plist and delete the other orientations which you don't need :- 解决方案1.转到info.plist并删除不需要的其他方向:-
Solution 2. Use following code(where your) :- 解决方案2.使用以下代码(在您所在的位置):
-(NSUInteger)supportedInterfaceOrientations {
UIViewController *vC = self.topViewController;
return vC.supportedInterfaceOrientations;
}
-(BOOL)shouldAutorotate {
UIViewController *vC = self.topViewController;
return [vC shouldAutorotate];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.