gpt4 book ai didi

iphone - ImagePicker 中的 View 层次问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:27:02 24 4
gpt4 key购买 nike

我想不出执行某些任务的最有效和“优雅”的方法。问题定义是:我想显示几个 View ,其中之一是带有相机胶卷源的 ImagePicker。

层次结构类似于:主视图 ---> 选择器 ---> 图像处理 View 当用户点击“后退按钮”时,UI 必须允许向后显示。

我尝试了几种选择:

1.

a) MAIN VIEW 以模态方式呈现选择器 View 。b) 在 didFinishPickingMediaWithInfo 委托(delegate)方法中关闭选择器模态视图,然后使用图像处理 View 调用 presentModalViewController。

示例代码:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage* pickedImage = [info valueForKey:UIImagePickerControllerEditedImage];
LastViewController* vc = [[LastViewController alloc] init];
vc.mainImage = pickedImage;

[self dismissModalViewControllerAnimated:NO];

[self presentModalViewController:vc animated:NO];
}

问题是,它不起作用,因为 Controller 在关闭另一个模态后无法显示下一个模态(上一个模态不会立即消失,MAIN 不会立即激活,也无法显示新模态)。

2。主视图以模态方式呈现图像处理 View ,但紧接着图像处理 View 以模态方式呈现选择器 View ,等待完成,关闭选择器,用户可以看到带有库中图像的图像处理 View 。

示例代码:

在主视图 Controller 的一些 Action 中:

ImageProcessViewController *vc = [[ImageProcessViewController alloc] initWithNibName:@"ImageProcessViewController" bundle:nil];
vc.delegate = self;
vc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:vc animated:NO];
[vc release];

在 ImageProcessViewController 中:

- (void)viewDidLoad {
[super viewDidLoad];

//some UI init here

if(self.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
ipc.delegate = self;
ipc.allowsEditing = YES;
[self presentModalViewController:ipc animated:NO];
[ipc release];
}
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage* pickedImage = [info valueForKey:UIImagePickerControllerEditedImage];
self.mainImage = pickedImage;

[self dismissModalViewControllerAnimated:NO];
}

问题是,我无法在 viewDidLoad 方法中调用 presentModalViewController,因为它不起作用(我猜这在 View Controller 生命周期中还为时过早)。我也在 viewDidAppear 中尝试过,但在那种情况下,我必须设置一些 ivar 标志,只显示一次选择器 View ,并且在图像选择器 View 之前短时间显示空图像处理 View ,我不想要这个。

3。我试图弄清楚如何使用 Navigation Controller 来执行此操作,因为 UIImagePickerController 正在使用他的导航 Controller ,但这是私有(private)结构,文档说程序员不能这样做。

请给我一些建议,因为我现在真的迷路了

最佳答案

在您的主视图 Controller 中,使用 viewDidAppear:animated: - 这将在模式转换完成时调用。您可以从那里安全地开始另一个模式转换。

关于iphone - ImagePicker 中的 View 层次问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5042103/

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