iOS 11安全区域布局指导向后兼容性 [英] iOS 11 safe area layout guide backwards compatibility

查看:138
本文介绍了iOS 11安全区域布局指导向后兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启用安全区域布局指南是否与iOS 11以下兼容?

Is enabling Safe Area Layout Guides compatible to iOS below 11?

推荐答案

我设法使用新的安全区布局指南并保持与iOS 9和iOS 10的向后兼容性:
(编辑:正如@NickEntin在评论中所指出的,这个实现将假定有一个状态栏存在,这在iPhone X的横向上是不正确的。导致到顶部的空间很大(20分)。然而它将完全正常运行。

I managed to work with the new Safe Area layout guides and maintain backwards compatibility with iOS 9 and iOS 10: ( as pointed out in the comments by @NickEntin, this implementation will presume there is a status bar present, which won't be true in landscape on the iPhone X. Resulting in to much space to the top (20 points). It will run perfectly fine however.

例如,如果您希望视图位于状态栏下方10个点(并且iPhone X上传感器外壳下方10个点):

E.g. if you want a view to be 10 points below the status bar (and 10 points below the sensor housing on iPhone X):


  1. 在您的XIB中,转到文件检查器并启用保险箱,方法是检查使用安全区域布局指南

  2. 从视图顶部到主视图顶部创建一个约束,> = (大于或等于)约束,常量 30 (30因为我们希望10个点间距到状态栏,即20点高)和优先级(750)。

  3. 从视图顶部到安全区域顶部创建约束, = (等于)约束,常量 10 和优先级(250)。

  1. In your XIB, go to File Inspector and enable the safe are by checking Use Safe Area Layout Guides.
  2. Create a constraint from the view's top to the main view's top, with >= (greater than or equal) constraint, constant 30 (30 because we want 10 points spacing to the status bar which is 20 points high) and priority High (750).
  3. Create a constraint from the view's top to the Safe Area's top, with = (equal) constraint, constant 10 and priority Low (250).

底部的视图(以及安全区的前/后或左/右)也可以这样做:

The same can be done for a view at the bottom (and for leading/trailing or left/right to the Safe Area):


  1. 在您的XIB中,转到文件检查器并通过检查<$ c $启用保险箱c>使用安全区域布局指南。

  2. 从视图底部到主视图底部创建约束,> = (大于或等于)约束,常量 10 和优先级(750)。

  3. 从视图底部到安全区域底部创建约束, = (等于)约束,c onstant 10 和优先级(250)。

  1. In your XIB, go to File Inspector and enable the safe are by checking Use Safe Area Layout Guides.
  2. Create a constraint from the view's bottom to the main view's bottom, with >= (greater than or equal) constraint, constant 10 and priority High (750).
  3. Create a constraint from the view's bottom to the Safe Area's bottom, with = (equal) constraint, constant 10 and priority Low (250).

这篇关于iOS 11安全区域布局指导向后兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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