Wenn ich ein Foto mit meinem iPad nehmen, erscheint die folgende Meldung auf der Konsole:Warnung, wenn ich ein Foto mit einem iPad
Snapshot-Erstellung eine Ansicht, die nicht zu einer leeren Schnappschuss gemacht hat. Stellen Sie sicher, dass Ihre Ansicht mindestens einmal vor dem Snapshot oder Snapshot nach Bildschirmaktualisierungen gerendert wurde.
Dies ist mein Code, um ein Foto und speichern Sie es zu nehmen:
- (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];
}
Und das neue Bild erhalten:
- (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];
}
Warnung wird angezeigt, wenn ich in Nehmen Foto klicken.
Dies ist praktisch das gleiche wie ich in meinem Code. Arbeite nicht für mich. – ivan180593