2 starwar2012 starwar2012 于 2013.08.13 16:31 提问

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
zhanglei5415   Rxr 2013.08.14 10:48
已采纳

shouldAutorotate return NO,改成return YES试试

- (BOOL) shouldAutorotate
{
    return YES;
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!