【发布时间】:2016-09-02 13:40:12
【问题描述】:
当我使用 iPad 拍照时,控制台上会显示以下消息:
对尚未渲染的视图进行快照会导致快照为空。确保您的视图在快照之前或屏幕更新后的快照之前至少渲染过一次。
这是我拍摄照片并保存的代码:
- (IBAction)selectPhoto:(id)sender {
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* camera = [UIAlertAction actionWithTitle:@"Take Photo" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
_imagePickerController = [[UIImagePickerController alloc] init];
_imagePickerController.allowsEditing = YES;
_imagePickerController.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[_imagePickerController setSourceType: UIImagePickerControllerSourceTypeCamera];
_imagePickerController.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:_imagePickerController animated:YES completion:nil];
}
else {
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"Camera not detected"
message:@""
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
}];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];
}
}];
[alertController addAction:camera];
[alertController.view layoutIfNeeded];
UIPopoverPresentationController *pop = alertController.popoverPresentationController;
alertController.popoverPresentationController.sourceRect = self.button.frame;
alertController.popoverPresentationController.sourceView = self.view;
pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
pop.delegate = self;
[self presentViewController:alertController animated:YES completion:nil];
}
并获取新图像:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.image"]){
_img = [info objectForKey:UIImagePickerControllerEditedImage];
[_button setBackgroundImage:_img forState:UIControlStateNormal];
[_button setTitle:@"" forState:UIControlStateNormal];
}
[self.imagePickerController dismissViewControllerAnimated:YES completion:nil];
}
点击拍照时出现警告。
【问题讨论】:
标签: ios objective-c uiimagepickercontroller photo