2013-01-17 29 views
1

我有一個很奇怪的現象:的UIImagePickerController在iOS 6中不能正常工作

  1. 在iOS 5中我以這種方式呈現UIImagePickerController

imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.modalPresentationStyle = UIModalPresentationFullScreen; imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentModalViewController:imagePicker animated:YES];

現在在iOS 6中會產生崩潰。我通過UIImagePickerController寫一個類解決了崩潰:

@implementation UIImagePickerController (NonRotating) 

- (BOOL)shouldAutorotate 
{ 
    return NO; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskAll; 
} 

@end 

的問題是,現在的UIImagePickerController不旋轉,它的顯示上側。而且,當我按下「取消」按鈕並且選取器被解散時,應用程序再次崩潰。

  1. 如果我使用UIImagePickerController一個UIPopoverController內,一切工作正常(屬於事實酥料餅不旋轉),但是當我駁回酥料餅在我的應用視圖控制器停止響應旋轉事件這導致所有應用都被阻止在這個方向上。要恢復正確的行爲,我需要從後臺退出應用程序並再次打開。

這是代碼我使用的顯示酥料餅

_cameraPopoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker]; 
[_cameraPopoverController presentPopoverFromRect:_takeFromCamera.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

這個問題讓我瘋狂!

+0

'presentModalViewController:動畫:'在IOS 6中棄用這不應該崩潰您的應用程序,但也許你應該嘗試'presentViewController:動畫:完成:'來代替。 –

回答

0

什麼是您的選取器來源類型? 照片庫/相冊或相機膠捲?

假設你正在使用圖片庫/相冊源,在iPad上,你必須使用一個酥料餅:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html(看看概述,4點)

呈現全屏它不支持。

關於另一個問題(在解散popOver之後,其他VC停止旋轉)檢查您是否擁有強大的對popover(強屬性)的引用。 粘貼您用於呈現彈出窗口的代碼。

+0

我使用UIImagePicker控制器從相機拍攝照片。 編輯我的代碼的問題。 – Fry

+0

Mmmhh,好了,你可以模態或酥料餅的出現,它是相同的。我會做的第一件事情:試着理解爲什麼它出現時崩潰*沒有*類別。你看到日誌上有什麼?如果你放置一個異常斷點,會發生什麼?此外,該類別似乎沒有一個很好的解決方案,你想在類別覆蓋的方法,可能的,但在原來的UIImagePickerController實現。這樣做會給你意想不到的行爲。看到這個http://stackoverflow.com/questions/5272451/overriding-methods-using-categories-in-objective-c – LombaX

+0

這是日誌時,應用程序崩潰**終止應用程序由於未捕獲的異常「UIApplicationInvalidInterfaceOrientation」,原因:' preferredInterfaceOrientationForPresentation必須返回一個支持的接口方向!** – Fry

0

雖然我不建議使用類別覆蓋影像選擇器的默認行爲,有在實現中的錯誤導致提到的死機:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationMaskPortrait; 
           ~~~~ 
} 

返回值不應該是一個方向面具,它應該是一個方向,例如UIInterfaceOrientationPortrait。

相關問題