前提:项目是横屏的,最近在做调用摄像头和相册的功能,已经合并到项目工程中。
问题:出现一个问题,就是如果是不开放竖屏权限,那么打开相册或者摄像头就会报错,程序直接退出。
*** Terminating app due to uncaught exception ‘UIApplicationInvalidInterfaceOrientation’, reason: ‘Supported orientations has no common orientation with the application, and is returning YES’
解决办法:开放横竖屏接口有两种:
- app 级别的可以在[target]-[general]-[device orientation]里面设置,勾选Portrait复选框;
2.viewController级别,就是在appcontroller中添加函数支持
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { // return UIInterfaceOrientationMaskAll; // 个人建议使用这个函数,不开放UpsideDown权限,具体原因参考下面第一个链接 return UIInterfaceOrientationMaskAllButUpsideDown; } ``` 在 RootViewController中添加- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return UIInterfaceOrientationIsLandscape( interfaceOrientation ); } // For ios6, use supportedInterfaceOrientations & shouldAutorotate instead - (NSUInteger) supportedInterfaceOrientations{ #ifdef __IPHONE_6_0 return UIInterfaceOrientationMaskPortraitUpsideDown; #endif } - (BOOL) shouldAutorotate { return YES; } ``` 还有问题:但是,这个还没有解决我的问题,因为开放了竖屏权限,所以我的项目现在也可以竖屏显示,而我的本意只是让调用相册和摄像头的时候竖屏,其他时刻还是只能横屏显示,请问各位大牛们怎么解决这个问题。 已解决: 解决办法是:修改// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead - (NSUInteger) supportedInterfaceOrientations{ #ifdef __IPHONE_6_0 return UIInterfaceOrientationMaskPortraitUpsideDown; #endif } ``` 为:// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead - (NSUInteger) supportedInterfaceOrientations{ #ifdef __IPHONE_6_0 // return UIInterfaceOrientationMaskPortraitUpsideDown; return UIInterfaceOrientationMaskLandscape; #endif } ``` http://www.2cto.com/kf/201504/393303.html http://www.cocoachina.com/bbs/read.php?tid=116350&keyword=UIApplicationInvalidInterfaceOrientation