全屏后导航栏下的UIView [英] UIView under Navigation Bar after full screen

查看:66
本文介绍了全屏后导航栏下的UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有导航栏的应用程序.当我单击应用程序中的照片预览时,它会全屏显示照片.但是当我关闭全屏时,我的控制器的视图在导航栏下方.

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.

我在 StackOverflow 上看到有必要添加这一行:

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?

更新:

推荐答案

1- 使导航栏不透明.

1- Make your navigation bar opaque.

self.navigationController.navigationBar.translucent = NO;

2- 如果您使用 Xib,请在文件检查器中检查安全区域布局指南",如下所示.

2- If you are using Xib then check "Safe Area Layout Guides" in the File Inspector as shown below.

3- 如果您想以编程方式进行,则在添加视图后

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

这篇关于全屏后导航栏下的UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆