How to hide the iOS navigation bar correctly

Source: Internet
Author: User

In the project often hit the top of the homepage is infinite Carousel, need to rely on the top display. There are a number of ways to set the navigation bar to be transparent, and this can be done with a third party. Or simply rough directly hide the navigation bar. But push to the next page when the navigation bar is needed, how to do, here are two ways.

      • The first approach
        -Be sure to hide the navigation bar in an animated way, so it works best when you use the swipe to return gestures, which is consistent with the motion diagram above. One drawback of this is that there is an animation of the navigation bar disappearing when switching tabbar.
-(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];}

      • The second approach
        • Set the self as the navigation Controller agent, implement the proxy method, set the navigation bar to hide and display in the controller to be displayed, using this method not only fits the sliding return gesture perfectly, but also solves the problem that the navigation bar dynamically hides when switching tabbar.
@interface Wlhomepagecontroller () <UINavigationControllerDelegate> @end @implementation Wlhomepagecontroller # pragma mark-lifecycle-(void) viewdidload {    [super viewdidload];    Set the proxy for the navigation controller to self    self.navigationController.delegate = self;} #pragma mark-uinavigationcontrollerdelegate//will display Controller-(void) Navigationcontroller: (Uinavigationcontroller *) Navigationcontroller Willshowviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) Animated {    // Determine if the controller you want to display is your own    BOOL isshowhomepage = [Viewcontroller iskindofclass:[self class]];    [Self.navigationcontroller setnavigationbarhidden:isshowhomepage animated:yes];}

How to hide the iOS navigation bar correctly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.