gpt4 book ai didi

ios - 在 UIImagePickerController 中选择图像后,如何设置预览图像的 View ?

转载 作者:行者123 更新时间:2023-11-29 01:08:56 27 4
gpt4 key购买 nike

我想创建一个 View 来预览您在 UIImagePickerController 中选择的图像后的图像。我尝试创建一个 View Controller 并将选择器 Controller 推送到另一个 View Controller 。

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
ImagePreviewController *ipc = [self.storyboard instantiateViewControllerWithIdentifier:@"ImagePreviewController"];
UIImage * image = [info valueForKey:UIImagePickerControllerOriginalImage];

ipc.selectedImage = image;
[picker pushViewController:ipc animated:YES];
}

如您所见,我尝试将 UIImagePickerController 推送到另一个 View 并尝试预览它。但不幸的是,当我调试它时,ipc对象显示为null。我知道 UIImagePickerController 是从 UINavigationController 继承的。是因为在这个导航 Controller 中找不到我的ipc的 View 吗?如果是,我如何将它添加到 UIImagePickerController 中以便它可以推送到预览 ImageView ?如果没有,如何正确设置预览 ImageView ?

更新:如果我把

    ImagePreviewController *ipc = [ImagePreviewController alloc]init];

相反,当它按下时,它是黑屏。

最佳答案

您应该关闭图像选择器,然后呈现您的自定义 UIViewController 子类

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIViewController *presentingViewController = picker.presentingViewController;
ImagePreviewController *ipc = [self.storyboard instantiateViewControllerWithIdentifier:@"ImagePreviewController"];
UIImage * image = [info valueForKey:UIImagePickerControllerOriginalImage];

ipc.selectedImage = image;

[presentingViewController dismissViewControllerAnimated:YES completion:^(BOOL animated){
[presentingViewController presentViewController:ipc animated:YES completion:nil];
}];
}

关于ios - 在 UIImagePickerController 中选择图像后,如何设置预览图像的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36001397/

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