imzyf / ios-swift-learning-notes

📝 iOS Swift Learning Notes - see Issues
MIT License
0 stars 0 forks source link

autolayout 相关 #99

Open imzyf opened 6 years ago

imzyf commented 6 years ago

leftAnchor:左边距 rightAnchor:右边距 topAnchor:上边距 bottomAnchor:下边距 widthAnchor:宽度 heightAnchor:高度 centerXAnchor:中心x centerYAnchor:中心y leadingAnchor:依赖语言环境设置,对于从左往右阅读语言,比如英语,leadingAnchor = leftAnchor,对于从右往左阅读语言,比如阿拉伯语,leadingAnchor = rightAnchor trailingAnchor:依赖语言环境设置,对于从左往右阅读语言,比如英语,trailingAnchor = rightAnchor,对于从右往左阅读语言,比如阿拉伯语,trailingAnchor = leftAnchor firstBaseLineAnchor:the baseline of the top row of text lastBaseLineAnchor:the baseline of the bottom row of text leading/trailing 同 left/right的区别

This was covered (briefly) in one of the WWDC 2015 videos on the Mysteries of Autolayout (I think it was part 1 but both are worth watching).

left和right约束是绝对的,总是意指屏幕的左侧和右侧。leading和trailing约束和设备的语言环境有关系。苹果官方的建议是使用leading和trailing约束,如果是绝对布局并且不在意语言环境设置,可以使用left和right约束。

imzyf commented 6 years ago

UIView的层次结构

在讨论Auto Layout前先来了解下UIView的层次结构,在iOS的视图中,最底层的是UIWindow(UIWindow当然也是从UIView继承而来),其上再是我们的View Controller的UIView,再上面则是我们自己拖拽的各种控件的UIView。要看到UIView的层次结构,可以通过Xcode的Debug View HieraHierarchy按钮来查看。

autoresizingMask并只支持父子视图之间进行约束,并不支持同级视图和跨级视图的布局

作者:七把刀 链接:https://www.jianshu.com/p/c6541ff0bdaf 來源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。