gpt4 book ai didi

ios - UIPickerView UIImage 和 Segue

转载 作者:行者123 更新时间:2023-11-29 02:53:45 26 4
gpt4 key购买 nike

在我的应用程序中,我在我的 UserView 中使用带有 UIImagePickerCollection 的相机。但是一旦用户选择“使用照片”,我希望将我的照片放在另一个 View 中,即“cameraView”,因为我需要进行一些处理。这是我的代码:

-(void)takeAPicture{
NSLog(@"CHEESE");
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];

imagePicker.delegate = self;

imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;

imagePicker.mediaTypes =
@[(NSString *) kUTTypeImage];

imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker
animated:YES completion:nil];
}

-(void)imagePickerController:
(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:^{
_img = [info objectForKey:UIImagePickerControllerOriginalImage];
if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(_img, nil, nil, nil);
}}];
[self performSegueWithIdentifier:@"toCameraView" sender:self];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:@"toCameraView"])
{
CameraViewController *transferViewController = segue.destinationViewController;
transferViewController.img = _img;
}
}

当我运行我的应用程序时,我收到一条警告消息:

Warning: Attempt to present <CameraViewController: 0x17e20eb0> on <EIUserViewController: 0x189b1000> while a presentation is in progress!

我不明白这是什么,以及如何处理它,我无法在其他 View 中接收我的图像并在选择“使用图片”后直接显示我的 View 。如果有人有解释或解决方案?谢谢你们!

最佳答案

您正在尝试在 UIImagePickerController 关闭期间 [self PerformSegueWithIdentifier:@"toCameraView"sender:self],换句话说:无法在第一个 VC 消失期间对出现的第二个 VC 进行动画处理。尝试移动 [self PerformSegueWithIdentifier:@"toCameraView"sender:self];在完成 block 内:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:^{
_img = [info objectForKey:UIImagePickerControllerOriginalImage];
if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(_img, nil, nil, nil);
[self performSegueWithIdentifier:@"toCameraView" sender:self];
}}];
}

关于ios - UIPickerView UIImage 和 Segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24164618/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com