简体   繁体   English

如何在另一个控制器下调出模态视图控制器?

[英]How can I bring up a modal view controller under another one?

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. 在屏幕A上开始。当按下按钮时,屏幕B动画为模态视图控制器,覆盖A.在第一个场景中,当屏幕B被解除时,它向下滑动显示屏幕C,这是一个新的模态视图控制器,现在覆盖屏幕A.当C被解除时,它向下滑动以再次显示屏幕A. In the second scenario when screen B is dismissed it reveals modal screen D covering screen A. 在屏幕B被解除的第二种情况下,它显示覆盖屏幕A的模态屏幕D.

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. 我最大的问题是我无法找到一种方法在B被解雇之前显示模型对话框C或D,并且直到B中发生某些事情,我不知道我是否应该创建C或D,所以我不能从C的父母B开始。 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? 有什么想法我可以让这个场景有效吗?

Strategy one: if it would suit your app, consider using navigation controllers rather than modals. 策略一:如果它适合您的应用,请考虑使用导航控制器而不是模态。 NSNavigationController has a handy method: NSNavigationController有一个方便的方法:

- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated

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. 因此,可能更改堆栈以在没有动画的情况下将新VC插入到顶部(当前的一个)之下。 Then your Done button (or similar) pops the top VC to reveal the new one underneath. 然后你的完成按钮(或类似的)弹出顶部VC以显示下面的新VC。

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. 例如,对于VC A,请实现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 (ie show modal without animation) because the dismiss animation for the above VC has just begun. 这个方法通常在UI被忽略的动画开始时被调用,并且可能是插入新VC(即没有动画的show modal)的好地方,因为上面的VC的解雇动画刚刚开始。 As I say, your mileage may vary. 正如我所说,你的里程可能会有所不同。

see the Apple docs Apple文档

"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. 所以你可以模态地呈现NavigationControllers。

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. 另一种方法是以模态方式呈现NavigationController,但是从一开始就在其上推送两个ViewControllers,以便用户看到第二个(屏幕B),然后返回到第一个(屏幕C),然后关闭模态NavigationController返回屏幕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. 由于这不是特别理想,我们最终改变了导航结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式在一个中央视图控制器下设置多个自定义UIViewController? - How do I set up several custom UIViewControllers under one central view controller programmatically? 我可以从另一个模态视图控制器中推送模态视图控制器吗? - Can I push a modal view controller from within another modal view controller? 如何设置模态视图 controller 的标题栏标题? - How can I set the titlebar title for a modal view controller? 选择联系人后如何显示模态视图控制器? - How can I present a modal view controller after selecting a contact? 如何从另一个iOS访问一个控制器的表视图委托方法 - How can I access a table view delegate methods of one controller from another ios 如何将信息从一个视图控制器中的表视图单元传递到另一视图控制器? - How do I pass information from a table view cell in one view controller to another view controller? 如何在iPhone的一个标签下显示视图和子视图? - How can I have a view and a subview under one tab on the iphone? 如何从一个视图重定向到Master View Controller - How can i redirect to Master View Controller from one view 如何更换模态视图控制器? - How do I replace a modal view controller? 如何在一个视图 controller 从另一个视图 controller 访问变量? - How do I access a variable in one view controller from another view controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM