The combination of iOS custom return button and system slide.

Source: Internet
Author: User

The combination of iOS custom return button and system slide.
When we use a Custom button for popViewController and hide the system NavigationBar,

(Self. navigationController. navigationBarHidden = YES ;)

The slide gesture of the NavigationBar system does not exist.

Of course, we can add slide gestures to the current view, but it is prone to bugs, especially the view that contains views such as scrollview and tableview.

The following describes a clever method to combine the custom backBtn with the system slide:


- (void)viewWillAppear:(BOOL)animated {    [super viewWillAppear:animated];    self.navigationController.navigationBar.alpha = 0;        //    self.navigationController.navigationBarHidden = YES;}- (void)viewWillDisappear:(BOOL)animated {    [super viewWillDisappear:animated];    self.navigationController.navigationBar.alpha = 1;        //    self.navigationController.navigationBarHidden = NO;}

As you can see, the NavigationBar is not hidden, but the transparency is adjusted to 0. If the transparency is 0, the NavigationBar will not occupy the position,

However, the slide function is still in progress. During the process, it is found that the backBtn and title of the system NavigationBar are displayed when the side slides in half,

Therefore, the two items can be set to nil. Note: These settings for NavigationBar take effect globally,

Make sure that the corresponding processing is completed at different stages of the view lifecycle.


To sum up, if we want to use the system NavigationBar view instead of its slide gesture,

To use the view life cycle flexibly

 self.navigationController.navigationBar.alpha = 0; self.navigationController.navigationBar.alpha = 1;
The system NavigationBar's backItem and other Members may be hidden in due time. 



Related Article

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.