簡體   English   中英

當UIAlertview在Landscape viewcontroller中顯示時,shouldAutorotate()方法崩潰嗎?

[英]Crash on shouldAutorotate() method when UIAlertview show in Landscape viewcontroller?

我正在開發一個僅使用一個方向(即人像)的應用程序。 這是設備方向設置:

在此處輸入圖片說明

但是在我的應用程序中,我只想在“橫向右”模式下顯示視頻播放器( MPMoviePlayerViewController自定義播放器),並且不應旋轉它。 一切正常,我的意思是該自定義播放器在“橫向右移”中完美顯示,但是當我使用UIAlertview應用程序在此方法上崩潰了:

- (BOOL)shouldAutorotate {


    return NO;

}

這些是其他一些定向方法:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeRight; // or Right of course
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)supportedInterfaceOrientations
#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif
{
    return UIInterfaceOrientationMaskLandscape;
}

我收到此錯誤:

 *** 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

#import "UIAlertController+Portrait.h"

@implementation UIAlertController (Portrait)

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

@end

iHTCboy的答案在轉換為swift后為我解決了。

快速4:

extension UIAlertController {

override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .all }

}

解決方案1.轉到info.plist並刪除不需要的其他方向:-

在此處輸入圖片說明 解決方案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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM