问题
Navigation gap appears when swipe from large title page to small title page!
回答1:
Make sure, you just need to check Translucent selected from the storyboard.
Set in code like this
override func viewWillAppear(_ animated: Bool) {
if #available(iOS 11.0, *) {
self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationController?.navigationItem.largeTitleDisplayMode = .automatic // Change Display Mode
}else{
// Fallback on earlier versions
}
}
Outout :
回答2:
The view's layout starts from the bottom of the navigation bar. When transit from large title page to small title page, the navigation bar becomes shorter, then the navigation gap appears.
To resolve this problem, the layout of the controller's view should start from the zero point of the screen, and it's subviews' layout should start from the bottom of the navigation bar to prevent from being covered.
Two properties can effect the layout: translucent and edgesForExtendedLayout. The translucent property should be set to YES, or delete it everywhere(It's default value is YES). The edgesForExtendedLayout property should be set to UIRectEdgeAll, or delete it everywhere(It's default value is UIRectEdgeAll).
For UITableViewController's page, it will automatically adjust to the navigationbar(tableview's adjustedContentInset will change, the premise is set contentInsetAdjustmentBehavior to UIScrollViewContentInsetAdjustmentAutomatic, or delete the setting), any other code should not change.
For UIViewController, the subviews' of the main view should adjust its layout to the bottom of the navigation bar. The example code like,
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.searchBgTopLayoutConstraint.constant = NORMAL_STATUS_AND_NAV_BAR_HEIGHT;
#top constraint of the top most view
}
If the first view (A) of the subviews inherits from UIScrollView, and the large title will change according to the A's scroll. The detail can be found in Shrink large title when scrolling (not UITableViewController) iOS 11 .
If the top most view inherites from UIScrollView, like mainTableView, you can set its layout start from the zero point, and set its contentInset to the bottom of the navigation bar. It looks like an UITableViewController, and the navigation bar changes when mainsTableView scrolling, without any white space. The example code like,
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.mainTableView.contentInset = UIEdgeInsetsMake(NORMAL_STATUS_AND_NAV_BAR_HEIGHT, 0, 0, 0);
}
来源:https://stackoverflow.com/questions/54800343/navigation-gap-appears-when-transition-from-large-title-page-to-small-title-page