ios6:UIImagePickerController & Rotation
项目是在ipad上的横屏的项目,运行在ios6上时,在用到选择本地相册的时候崩溃:
“Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES”
一查原来是ios6的rotation较之前有了改动。ios6丢弃了shouldAutorotateToInterfaceOrientation的方法,代替的是supportedInterfaceOrientations 、shouldAutorotate 、preferredInterfaceOrientationForPresentation等方法,具体变化见:iOS 6的Rotation
因为项目要求是全部横屏,但是UIImagePickerController又是竖屏显示的。违反了ios6对Rotation的新规定。最终在http://code4app.com/requirement/5074e36b6803fa8445000000
找到答案。
在appdelegate添加
#if __IPAD_OS_VERSION_MAX_ALLOWED >= __IPAD_6_0 - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationAllMask; } #endif
然后在你UIImagePickerController的top-most VC中添加:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft||interfaceOrientation==UIInterfaceOrientationLandscapeRight); } //ios 6 rotation -(NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationLandscapeMask; } - (BOOL)shouldAutorotate { return YES; }
问题解决!
作者:老Zhan
出处:http://www.cnblogs.com/mybkn/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。