Present Modal View Controller On Top of UINavigationController

余生颓废 提交于 2019-12-10 16:25:16

问题


I have my app that is below a UINavigationController and therefore below a UINavigationBar. I want to present a Modal View Controller on top of this UINavigationBar because the controller I wrote doesn't make sense if it's below it (that is, I want to hide the navigation bar when showing this view controller).

Presenting it with this code:

    ukc = [[UnlockKeyboardViewController alloc] init];
    [self presentModalViewController:ukc animated:NO];

Cause the Modal view controller to be below the UINavigationBar. That UINavigationBar shouldn't show up when I show this modal view. How can I go around that?

PS: This is a jailbreak app, so there's no Interface Builder.


回答1:


[self.navigationController presentModalViewController:ukc animated:NO];



回答2:


Extra info upon working with a related issue:

note173's answer works with animated:YES too. The user will see ukc's view slide up over the nav stack.

And if you subsequently need to dismiss ukc and return to self's view, do this:

        [self.navigationController dismissModalViewControllerAnimated:NO];
        [self.navigationController dismissModalViewControllerAnimated:YES]; 

The first call dismisses ukc. The second call dismisses the nav controller. What the user sees is ukc's view sliding down to reveal self's view, with a glimpse of the navigation stack behind it.

So what you have here is a way of switching directly from the nav stack to some other regular view controller, and then back to a base view controller, all with animations that make sequential sense.

(If your aim was to switch back and forth between the nav stack and ukc, you would dismiss ukc with one call -- self.navigationController dismissModalViewControllerAnimated:YES]; which would slide ukc's view down to reveal the nav stack.)

Note that these methods are deprecated in iOS 5. I assume presentViewController and dismissViewControllerAnimated would do the same thing, but I haven't tested them.



来源:https://stackoverflow.com/questions/11658193/present-modal-view-controller-on-top-of-uinavigationcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!