当我在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中运行。 我是这个网站的新用户,请帮忙。
答案 0 :(得分:1)
UIImagePickerController
仅在Potratin
模式下显示在iPhone中。我发现你的代码中还有一个错误,你使用的是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
答案 1 :(得分:1)
在启动@implementation之前在ViewController.m文件中编写以下代码
@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];
答案 2 :(得分:0)
如果是这样的话,请尝试this ...
将此添加到您的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;
}