问题
I have an application with a navigation bar. When I click on a photo preview in my application, it displays the photo in full screen. But when I close the full screen, the view of my controller is under the navigation bar.
I saw on StackOverflow that it was necessary to add this line:
self.edgesForExtendedLayout = []
It works but it creates another bug. So I would like to know if there was another alternative?
UPDATE :
回答1:
1- Make your navigation bar opaque.
self.navigationController.navigationBar.translucent = NO;
2- If you are using Xib then check “Safe Area Layout Guides” in the File Inspector as shown below.
3- And if you want to do it programmatically then after adding on view
self.yourView.translatesAutoresizingMaskIntoConstraints = false;
if (@available(iOS 11, *)) {
UILayoutGuide * guide = self.view.safeAreaLayoutGuide;
[self.yourView.leadingAnchor constraintEqualToAnchor:guide.leadingAnchor].active = YES;
[self.yourView.trailingAnchor constraintEqualToAnchor:guide.trailingAnchor].active = YES;
[self.yourView.topAnchor constraintEqualToAnchor:guide.topAnchor].active = YES;
[self.yourView.bottomAnchor constraintEqualToAnchor:guide.bottomAnchor].active = YES;
}
来源:https://stackoverflow.com/questions/41186443/uiview-under-navigation-bar-after-full-screen