如何在另一个模态视图控制器下调出模态视图控制器?
我有导航问题。我想创建以下导航结构:
从屏幕 A 开始。按下按钮时,屏幕 B 将作为模态视图控制器向上动画,覆盖 A。在第一个场景中,当屏幕 B 关闭时,它会向下滑动以显示屏幕 C,这是一个新的模态视图控制器,现在覆盖屏幕 A。当 C 被关闭时,它会向下滑动以再次显示屏幕 A。在第二种情况下,当屏幕 B 被关闭时,它会显示模态屏幕 D 覆盖屏幕 A。
我最大的问题是,我无法找到一种方法来在 B 被关闭之前以及发生某些事情之前显示 B 后面的模型对话框 C 或 D在B中,我不知道是否应该创建C或D,所以我不能从C开始将B作为父级。此外,即使我可以做到这一点,我也无法让动画按照我在问题陈述中描述的那样工作。
我有什么想法可以让这个场景发挥作用吗?
I have a navigation problem. I want to create the following navigation structure:
Start on screen A. When a button is pressed, screen B animates up as a modal view controller, covering A. In the first scenario, when screen B is dismissed it slides down revealing screen C, which is a new modal view controller now covering screen A. When C is dismissed, it slides down to reveal screen A again. In the second scenario when screen B is dismissed it reveals modal screen D covering screen A.
My biggest problem is that I can't find a way to display the model dialogs C or D behind B before it is dismissed, and until something takes place in B, I don't know if I should be creating C or D, so I can't parent B off of C to start with. Additionally, even if I could do that I can't get the animations to work as I described in the problem statement.
Any ideas how I might make this scenario work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
策略一:如果适合您的应用,请考虑使用导航控制器而不是模式。
NSNavigationController
有一个方便的方法:它可以让你重新组织视图控制器堆栈,无论有没有动画。因此,也许更改堆栈以将新的 VC 插入顶部(当前的 VC)下方而不使用动画会起作用。然后,您的“完成”按钮(或类似按钮)会弹出顶部 VC,显示下面的新 VC。
策略二:这是一个更具实验性的方法,可能行不通,但您可能会通过“及时”视图控制器插入而逃脱惩罚。例如,对于 VC A,实现
viewWillAppear。
此方法通常在其上方的 UI 动画开始时被调用,并且可能是插入新 VC 的好地方(即显示没有动画的模态),因为上述 VC 的关闭动画刚刚开始。正如我所说,您的里程可能会有所不同。Strategy one: if it would suit your app, consider using navigation controllers rather than modals.
NSNavigationController
has a handy method:which lets you reorganise the view controller stack, with or without animation. So perhaps changing the stack to insert the new VC below the top (current one) without animation would work. Then your Done button (or similar) pops the top VC to reveal the new one underneath.
Strategy two: this is a little more experimental and may not work, but you may get away with doing 'just in time' view controller insertion. For example, for VC A, implement
viewWillAppear.
This method usually gets called right at the start of the animation of a UI above it being dismissed, and may be a good place to insert a new VC (i.e. show modal without animation) because the dismiss animation for the above VC has just begun. As I say, your mileage may vary.请参阅 Apple 文档
“任何视图控制器对象都可以即使对于本身以模态方式呈现的视图控制器也是如此。换句话说,您可以根据需要将模态视图控制器链接在一起,从而呈现新的模态视图控制器。根据需要位于其他模态视图控制器之上。”
因此您可以以模态方式呈现导航控制器。
但是,您无法轻松切换导航控制器的根视图控制器(一种可能性 在这里)。
另一种方法是以模态方式呈现 NavigationController,但从一开始就在其上推送两个 ViewController,以便用户看到第二个(屏幕 B),然后返回到第一个(屏幕 C),然后关闭返回的模态 NavigationController到屏幕 A。
see the Apple docs
"Any view controller object can present any other single view controller modally. This is true even for view controllers that were themselves presented modally. In other words, you can chain modal view controllers together as needed, presenting new modal view controllers on top of other modal view controllers as needed."
So you can present NavigationControllers modally.
However, you can't switch the root view controller of a navigation controller easily (one possibility is here).
An alternative would be to present the NavigationController modally but push two ViewControllers on it from the get-go so the user sees the second one(screen B), then goes back to the first(screen C) and then dismisses the modal NavigationController going back to screen A.
看来使用标准模态视图控制器场景这是不可能的。我能找到的唯一解决方案是将其制作成单个视图控制器并使用自定义动画。由于这不是特别理想,我们最终改变了导航结构。
It appears that this is not possible using the standard modal view controller scenario. The only solution I could find was to make this into a single view controller and use custom animations. Since this was not particularly desirable, we ended up changing the navigation structure.