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.