UIView under Navigation Bar after full screen

1.6k Views Asked by At

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 :

enter image description here

1

There are 1 best solutions below

0
On

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. enter image description here

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;
}