2013-08-12 30 views
1

我想使用此代碼在我的應用程序中打開UIImagePickerController對象:的UIImagePickerController iOS中不開放6.0

self.imgPicker = [[UIImagePickerController alloc] init]; 
    self.imgPicker.delegate = self; 
    self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    self.imgPicker.modalPresentationStyle = UIModalPresentationFullScreen; 
    [self presentViewController:self.imgPicker animated:YES completion:nil]; 

但隨後的應用程序崩潰,並顯示以下錯誤:

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 
'preferredInterfaceOrientationForPresentation must return a supported interface orientation!' 

我在我的ViewController中還添加了以下方法

- (BOOL) shouldAutorotate 
{ 
    return NO; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationPortrait; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation { 

    return UIInterfaceOrientationMaskPortrait; 
} 

那麼,我還應該做些什麼來提出這個UIImagePickerController

+0

檢查這個http://stackoverflow.com/questions/12690963/preferredinterfaceorientationforpresentation-must-return-a-supported-interface-o – Manthan

+0

iPhone或iPad? –

回答

1

這似乎是因爲選擇照片VC沒有實現新的定位方法。要解決這個問題,請確保根目錄視圖控制器確實實現了它們,即使頂級VC沒有。

在代碼:

@implementation UINavigationController (Rotation_IOS6) 
-(BOOL)shouldAutorotate { 
    return [self.topViewController shouldAutorotate]; 
} 
-(NSUInteger)supportedInterfaceOrientations { 
    UIInterfaceOrientationMask topControllerOrientationMask = [self.topViewController supportedInterfaceOrientations]; 
    return topControllerOrientationMask ? topControllerOrientationMask : UIInterfaceOrientationMaskPortrait; 
} 
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
    UIInterfaceOrientation topControllerOrientation = [self.topViewController preferredInterfaceOrientationForPresentation]; 
    return topControllerOrientation ? topControllerOrientation : UIInterfaceOrientationPortrait; 
} 
@end 
0

關於死機的問題,你可以閱讀Here

而且shouldAutorotateToInterfaceOrientation必須返回不UIInterfaceOrientationMaskPortrait,但UIInterfaceOrientationPortrait, 約區別,你可以閱讀Here

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
    return UIInterfaceOrientationPortrait; 
} 
0

我覺得你試圖推出圖像拾取您的iPad上的應用程序。如果是這樣,你不能在iPad上啓動這種類型的選擇器,它只能在iPhone上運行。要在iPad上使用ImagePicker,請使用UIPopOver啓動imagePicker。

0

我前幾天有同樣的問題。我發現這個技巧。

將這個代碼在你

AppDelegate.m

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ 
    return UIInterfaceOrientationMaskAll; 
} 

而且也把這個代碼在你UIImagePickerViewController類。

- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

由於iOS-6UIImagePickerController必須遵循縱向。

+0

在AppDelegate.m中添加上面的方法,但不成功。錯誤繼續。 – ChandreshKanetiya

+0

@ ChandreshKanetiya-你有UINavigationController? – iPatel

+0

- (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; } – iPatel

相關問題