starwar2012 2013-08-13 08:31 采纳率: 0%
浏览 3134
已采纳

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条回答 默认 最新

  • ReyZhang 移动开发领域新星创作者 2013-08-14 02:48
    关注

    shouldAutorotate return NO,改成return YES试试

    - (BOOL) shouldAutorotate
    {
        return YES;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题