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,以支持所有的朝向

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章