从UIImagePickerController呈现另一个模态视图 [英] Present another modal view from UIImagePickerController

查看:99
本文介绍了从UIImagePickerController呈现另一个模态视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户拍照或选择已保存的照片后添加确认视图。确认视图将显示所选图像,工具栏中有取消和上传按钮。

I want to add a confirmation view after the user takes a photo or selects a saved photo. The confirmation view will just show the selected image, with a cancel and upload button in a toolbar.

我的UIImagePickerController是从我的一个视图控制器以模态方式呈现的,它是受控制的由导航控制器控制,然后由标签栏控制器控制。

My UIImagePickerController is presented modally from one of my view controllers, which is controlled by a navigation controller, which is in turn controlled by a tab bar controller.

如何以模态方式显示我的确认视图,以便它占据整个屏幕(如图像选择器视图)当用户选择照片时?理想情况下,我想要这样的东西:

How do I present my confirmation view modally so that it takes up the full screen (like the image picker view) when the user selects a photo? Ideally, I want something like this:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    UIViewController *modal = [[UIViewController alloc] init];
    modal.view = confirmationView;
    [self presentModalViewController:modal animated:YES];
    [modal release];
}

然而,这会导致应用程序崩溃。我应该从PICKER以模态方式呈现确认视图吗?如果是这样,我如何确保在确认视图被取消时,选择器也不会被显示?

However, that crashes the app. Should I be presenting the the confirmation view modally from the PICKER? If so, how do I make sure that when the confirmation view is dismissed, the picker will not be displayed either?

编辑:

修正了我发布的代码中的错误。当我尝试从内存而不是复制+粘贴中输入时会发生这种情况:(无论如何,到目前为止的建议都无济于事。

Fixed the bug in the code I posted. That's what happens when I try to type from memory instead of copy+paste :( Anyways, the suggestions so far don't help.

如果我提出模态控制器那么解雇选择器,没有任何反应,大概是因为两个控制器随后都被解雇了。

If I present the modal controller THEN dismiss the picker, nothing happens, presumably since both controllers are subsequently dismissed.

如果我解雇选择器然后出现模态控制器,我得到一个关于模态转换的例外: / p>

If I dismiss the picker THEN present the modal controller, I get an exception about modal transitions:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempting to begin a modal transition from <UINavigationController: 0x6b33940> to <UIViewController: 0x6b62b00> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed'


推荐答案

找到解决方案。事实上,挑选者需要被解雇,并且诀窍是关闭动画以解决这个问题所以它会立即发生,并且然后呈现第二个模态视图。

Found the solution. Indeed, the picker needs to be dismissed, and the trick is to turn animations off for that dismissal so it happens immediately, and then present the second modal view.

编辑:实际上,它让我几乎达到我想要的效果。当你关闭选择器时,原始视图会瞬间显示,然后模态视图会被动画化。这看起来有点时髦。

Actually, it gets me ALMOST to what I want. When you dismiss the picker, the original view gets shown for a split second, and then the modal view gets animated. This looks a little funky.

我也试图保持选择器而不是解雇它。相反,我调用 [picker presentModalViewController:modal animated:YES] 。这让我可以顺利地从选择器转换到确认视图。但是,当我完成确认视图时,我需要从原始控制器调用 [self dismissModalViewControllerAnimated:YES] 。这具有在解除所有内容之前首先显示图像选择器的效果。再一次,不是我想要的。

I also tried to keep the picker around and not dismiss it. Instead, I call [picker presentModalViewController:modal animated:YES]. This lets me smoothly transition from the picker to the confirmation view. However, when I'm done with the confirmation view, I need to call [self dismissModalViewControllerAnimated:YES] from the original controller. This has the effect of showing the image picker first before dismissing everything. Again, not quite what I want.

理想情况下,我想要与Facebook iPhone应用程序用于上传照片相同的效果。选择照片后,它会无缝转换为确认视图。从该视图中取消或确认将平滑过渡回原始主视图。这看起来像确认视图是图像选择器的一部分,当它可能只是另一个自定义视图。

Ideally, I want the same effect that the Facebook iPhone app uses for upload photos. Once you've selected a photo, it transitions seamlessly to a confirmation view. Canceling or confirming from that view will smoothly transition back to the original, main view. It makes it look like the confirmation view is part of the image picker, when it's probably just another custom view.

我该怎么做?

这篇关于从UIImagePickerController呈现另一个模态视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆