注:這個問題在最新的系統(tǒng)iOS11上是沒有問題的,但是我們要兼容之前的版本,最起碼要兼容iOS10的
在項目處于橫屏狀態(tài)下,調(diào)用相機或者相冊,出現(xiàn)崩潰,
報錯內(nèi)容為:'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES.
原因為當前的項目只支持橫屏,不支持豎屏,相冊只能在豎屏下顯示,這就導致的項目的崩潰
解決辦法就是在調(diào)用相機的時候,修改項目支持的方向,包含豎屏就可以,在AppDelegate中有一個項目支持的方向的方法,
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if (self.interfaceOri == 1) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}else if (self.interfaceOri == 2){
return UIInterfaceOrientationMaskLandscapeRight;
}else {
return UIInterfaceOrientationMaskPortrait;
}
}
只需要修改其中的self.interfaceOri參數(shù)(這個參數(shù)自己定義一個全局的數(shù)據(jù)就好,最好是某個單例里面的數(shù)據(jù))即可,系統(tǒng)會自動調(diào)用這個方法