问题
On iOS 13, when presenting a second modal view controller over a first one, the padding is incorrect on the button bar items. In particular, the right margin disappears.
How should this be fixed?
回答1:
This behavior is due to a bug in iOS 13. It can be fixed by calling setNeedsLayout on the Navigation Bar.
Swift example:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if #available(iOS 13.0, *) {
navigationController?.navigationBar.setNeedsLayout()
}
}
Objective-C example:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Fix navigation item placement on iOS 13: https://forums.developer.apple.com/thread/121861
if (@available(iOS 13.0, *)) {
[self.navigationController.navigationBar setNeedsLayout];
}
}
Credits: Solution borrowed from this thread on the Apple Developer Form.
来源:https://stackoverflow.com/questions/59842299/padding-wrong-when-presenting-second-modal-navigation-controller-on-ios-13