1

当我在 iPhone 上使用时,应用程序崩溃UIImagePicker了,但仅在iOS 7上。我使用以下代码行

    picker = [[UIImagePickerController alloc] init];

    picker.delegate = self;
    picker.allowsEditing = YES;

    if( [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] || [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])
    {
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    } else {
        //[self showAlertViewWithTitle:@"Sorry" message:@"Your Device Don't Have Camera"];
    }

    [self presentViewController:picker animated:YES completion:nil];

}

该应用程序在 iOS 6 上运行,而不是在 iOS 7 上运行。我是这个网站的新手,请帮忙。

4

3 回答 3

1

仅在iPhoneUIImagePickerController中以模式呈现。Potratin而且我发现您正在使用的代码中还有picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary一个isCameraDeviceAvailable错误:-

你应该这样编码: -

if( [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] || [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])
    {
       picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                 [self presentViewController:picker animated:YES completion:nil];
    } else {
         picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                 [self presentViewController:picker animated:YES completion:nil];       
    }

并在您的 ViewController 中shouldAutorotate更改为 NO 而不是 YES

于 2013-10-21T06:34:43.637 回答
1

在您的 ViewController.m 文件中,在开始 @implementation 之前编写以下代码

@interface NonRotatingUIImagePickerController : UIImagePickerController

@end

@implementation NonRotatingUIImagePickerController

- (BOOL)shouldAutorotate
{
    return NO;
}

@end

在要创建 Image Picker 对象的地方编写以下代码

UIImagePickerController* picker = [[NonRotatingUIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self; 
    [self presentModalViewController:picker animated:YES];
于 2013-10-21T06:46:45.740 回答
0

好的,如果是这种情况,试试这个......

将此添加到您的 ViewController

- (NSUInteger) supportedInterfaceOrientations
{
     //Because your app is only landscape, your view controller for the view in your
     // popover needs to support only landscape
     return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
于 2013-10-21T06:32:23.607 回答