xib文件中的安全区域布局指南 - iOS 10 [英] Safe area layout guides in xib files - iOS 10

查看:788
本文介绍了xib文件中的安全区域布局指南 - iOS 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始针对iPhone X调整我的应用,并在Interface Builder中发现了一个问题。
根据官方Apple视频,安全区域布局指南应该是向后兼容的。我发现它在故事板中运行得很好。

I started adapting my app for iPhone X and found an issue in Interface Builder. The safe area layout guides are supposed to be backwards compatible, according to official Apple videos. I found that it works just fine in storyboards.

但是在我的XIB文件中,安全区域布局指南在iOS 10中不受尊重。

But in my XIB files, the safe area layout guides are not respected in iOS 10.

它们适用于新操作系统版本,但iOS 10设备似乎只是假设安全区域距离为零(忽略状态栏大小)。

They work fine for the new OS version, but the iOS 10 devices seem to simply assume the safe area distance as zero (ignoring the status bar size).

我错过了所有必需的配置吗?这是一个Xcode错误,如果有,任何已知的解决方法?

Am I missing any required configuration? Is it an Xcode bug, and if so, any known workarounds?

以下是测试项目中的问题的屏幕截图(左iOS 10,右iOS 11):

Here is a screenshot of the issue in a test project (left iOS 10, right iOS 11):

推荐答案

安全区域布局和向后兼容性存在一些问题。请参阅我对此处的评论。

There are some issues with safe area layout and backwards compatibility. See my comment over here.

您可以解决其他约束问题,例如1000优先级> = 20.0到superview.top和750优先级== safearea.top。如果你总是显示一个状态栏,那应该可以解决问题。

You might be able to work around the issues with additional constraints like a 1000 priority >= 20.0 to superview.top and a 750 priority == safearea.top. If you always show a status bar, that should fix things.

更好的方法可能是为iOS 11和iOS-11之前的版本提供单独的故事板/ xib ,特别是如果你遇到的问题多于此。最好的原因是因为在iOS 11之前你应该将限制布局到顶部/底部布局指南,但对于iOS 11,你应该将它们放到安全区域。布局指南消失了。对于iOS 11之前的布局指南,在风格上比仅仅偏移20像素更好,即使结果与IFF一样,你总是会显示状态栏。

A better approach may be to have separate storyboards/xibs for pre-iOS 11 and iOS-11 and up, especially if you run into more issues than this. The reason that's preferable is because pre-iOS 11 you should layout constraints to the top/bottom layout guides, but for iOS 11 you should lay them out to safe areas. Layout guides are gone. Laying out to layout guides for pre-iOS 11 is stylistically better than just offsetting by a min of 20 pixels, even though the results will be the same IFF you always show a status bar.

如果您采用这种方法,则需要将每个文件设置为将在其上使用的正确部署目标(iOS 11或更早版本),以便Xcode不会向您发出警告并允许您使用布局指南或安全区域,取决于。在你的代码中,在运行时检查iOS 11,然后加载相应的storyboard / xibs。

If you take this approach, you'll need to set each file to the correct deployment target that it will be used on (iOS 11, or something earlier) so that Xcode doesn't give you warnings and allows you to use layout guides or safe areas, depending. In your code, check for iOS 11 at runtime and then load the appropriate storyboard/xibs.

这种方法的缺点是维护,(你将有两套您的视图控制器维护并保持同步),但是一旦您的应用程序仅支持iOS 11+或Apple修复向后兼容布局指南约束生成,您就可以摆脱iOS 11之前的版本。

The downside of this approach is maintenance, (you'll have two sets of your view controllers to maintain and keep in sync), but once your app only supports iOS 11+ or Apple fixes the backward compatibility layout guide constraint generation, you can get rid of the pre-iOS 11 versions.

顺便问一下,你如何显示你看到的控制器?它只是根视图控制器还是你提出它,或者......?我注意到的问题与推动视图控制器有关,所以你可能会遇到不同的情况。

By the way, how are you displaying the controller that you're seeing this with? Is it just the root view controller or did you present it, or..? The issue I noticed has to do with pushing view controllers, so you may be hitting a different case.

这篇关于xib文件中的安全区域布局指南 - iOS 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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