注:這個(gè)問(wèn)題在最新的系統(tǒng)iOS11上是沒(méi)有問(wèn)題的,但是我們要兼容之前的版本,最起碼要兼容iOS10的
在項(xiàng)目處于橫屏狀態(tài)下,調(diào)用相機(jī)或者相冊(cè),出現(xiàn)崩潰,
報(bào)錯(cuò)內(nèi)容為:'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES.
原因?yàn)楫?dāng)前的項(xiàng)目只支持橫屏,不支持豎屏,相冊(cè)只能在豎屏下顯示,這就導(dǎo)致的項(xiàng)目的崩潰
解決辦法就是在調(diào)用相機(jī)的時(shí)候,修改項(xiàng)目支持的方向,包含豎屏就可以,在AppDelegate中有一個(gè)項(xiàng)目支持的方向的方法,
- (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ù)(這個(gè)參數(shù)自己定義一個(gè)全局的數(shù)據(jù)就好,最好是某個(gè)單例里面的數(shù)據(jù))即可,系統(tǒng)會(huì)自動(dòng)調(diào)用這個(gè)方法