UIView under Navigation Bar after full screen

有些话、适合烂在心里 提交于 2020-06-27 17:32:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!