当我用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];
}
当我单击拍照时出现警告。
最佳答案
希望这可以帮助:
实用标记-UIImagePickerController委托
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *yourImage = info[UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:nil];
}
关于ios - 使用iPad拍照时出现警告,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37090040/