我开发了仅使用拍摄照片的横向模式项目和UIcamera图片控制器,但是当相机启动时它崩溃了并且它将显示以下原因:快照未渲染的视图会导致空快照。确保在屏幕更新后快照或快照之前至少渲染了一次视图。
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
// [self presentViewController:imagePicker animated:NO completion:^{
// [imagePicker setShowsCameraControls:YES];
// }];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"No camera available" message: @"Failed to take image" delegate: self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
答案 0 :(得分:0)
试试这位朋友:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No camera available" message:@"Failed to take image" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}