starwar2012
starwar2012
2013-08-13 08:31
采纳率: 79.3%
浏览 3.1k
已采纳

UIImagePickerController没打开

在应用中打开一个UIImagePickerController 对象。代码:

   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;
}

谢谢

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • zhanglei5415
    ReyZhang 2013-08-14 02:48
    已采纳

    shouldAutorotate return NO,改成return YES试试

    - (BOOL) shouldAutorotate
    {
        return YES;
    }
    
    点赞 评论

相关推荐