IOS上的UIApplicationInvalidInterfaceOrientation crash

  最近在游戏中加入一个打开本地相册选择图片上传的功能,在ios上使用了UiImagePicker,去显示相册,但是在iphone上运行的时候,会crash,并给出这样的信息:

'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES.


 在网上找了找原因,出现问题的原因是,UiImagePicker使用的uiviewcontroller只支持Portrait选择,而我们的游戏是一个landscape的游戏,在Appdelegate的- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window中也只支持了landscape。

 

一个viewcontroller支持的朝向在这个controller的

- (NSUInteger)supportedInterfaceOrientations中定义。

当一个viewcontroller启动时,它会根据当前的手机朝向和他的
shouldAutorotateToInterfaceOrientation接口来确定这个view的旋转,确定好后,还要看这个app的supportedInterfaceOrientationsForWindow中是否有它要做的朝向,如果没有就会crash。


在我们这个例子中,相册的view中的supportedInterfaceOrientations是只支持portrait的,但是我们的app的supportedInterfaceOrientationsForWindow没有portrait,就crash,在这里的解决办法就是将supportedInterfaceOrientationsForWindow中返回UIInterfaceOrientationMaskAll,以支持所有的朝向

posted on 2016-04-08 18:38  leonwei  阅读(1279)  评论(0编辑  收藏  举报