UINavigationController without NavigationBar
I have a "landing page/view" that I dont want the navigation bar to show, so I turn it off during the viewDidAppear
navigationBarHidden = YES;
When i push a view on the stack and th开发者_StackOverflow中文版en move it off. the main landing page shows the nav bar then hides it which cause a flicker that I dont want.
is there a way to have the landing page be a UIView or something? When a menu item is touched the app would push a new view on top of the default landing page. It sound like it would be hard to do without having the landing page be a UINavigationController. Any thoguhts?
Try hiding the navigation bar in viewWillAppear, rather than viewDidAppear.
If you don't need to go back to the landing page, use a view controller for the landing page and present it modally from the navigation controller when the application starts.
So you do want to go back to the landing page.
It's hard to accomplish that with UINavigationController
. Suppose your are going back to the landing view. While the transition, the old view should have a navigation bar, and the new view (landing page) should not have a navigation bar. UINavigationController
does not allow you manually modifying the transition animation. In other words, you cannot animate hiding/unhiding the navigation bar along with push/pop animation (using viewWillAppear
doesn't solve the problem).
So what would I do, if I really, really need this?
I would have a rootViewController (of UIViewController
), whose view is the only subview of your application window. When your application starts, rootViewController
add the landing view as a subview of its view. When the user selects an item there, you create an UINavigationController
with the corresponding view controller as its root view controller.
And, using CATransition
animation with type of kCATransitionPush
and subtype of kCATransitionFromRight
, you add the view of the navigation controller as a subview of rootViewController
's view.
Then you need a 'back' button for the first view of the navigation controller. In all view controllers that are the first level view controllers of the navigation controller, create a bar button item with a text 'Back', and add it to their navigationItem.leftBarButton
property. Set a target-action (probably to the rootViewController
) pair for the button.
When the action message fires, use CATransition
animation (now with kCATransitionFromLeft
subtype), to remove the current navigation controller's view from rootViewController
's view.
The transition may not look as perfect as the native UINavigationController
, but I believe this is the best you could get.
Actually the way to do this is to implement UINavigationController's delegate method navigationController:willShowViewController:animated
. This method is where you should handle hiding and showing your navigation bar so the animation will occur during the push/pop animation.
I came across a method that is simple and works well for me, and is not given here yet. I assume you have a view controller for the main landing page and it is set as root view controller of the navigation controller. Then you should hide/show the navigation bar in the viewWillAppear and viewWillDisappear methods of the main landing page controller:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
Source: http://www.iosdevnotes.com/2011/03/uinavigationcontroller-tutorial/
精彩评论