我经常以编程方式使用自动布局,但仍有两件事我不明白。

  1. leadingleft 属性/ anchor 之间以及trailingright 属性/ anchor 之间有什么区别?

对我来说似乎是一样的,但根据docs :

However, Auto Layout does not allow constraints that mix leading and trailing attributes with left or right attributes. As a result, this constraint crashes at runtime.

  1. NSLayoutConstraint 中的项目顺序对自动布局系统根本不重要,对吗? (至少对于 .Equal 关系。)

不要对每个单独项目的属性感到困惑,我知道这一点。

请您参考如下方法:

左和右永远是左和右。

前导和尾随不是。来自 Working with Constraints in Interface Builder :

If you lay out your views using leading and trailing constraints, the views automatically flip positions when switching between left-to-right languages (like English) and right-to-left languages (like Arabic). However, some interface elements should not change their position based on the reading direction. For example, buttons that are based on physical directions (up, down, left, and right) should always stay in the same relative orientation.

相等关系的项目顺序无关紧要。


评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

ios之获取 UIImageView 中图像的大小