[英]how to pin the view/object at the relative same place on different iPhone size?
如@Azat所建议的,我们可以使用“ UIScreen.mainScreen()。bounds.height”在运行时基于不同的iPhone尺寸获取不同的高度,从而可以将视图动态地布置在相对固定的位置。 对于上述问题描述中的示例:
对于1,2,3,4,5,我们可以在函数中编写代码,然后在viewDidLoad中调用它,例如:
func viewLayout() {
let bottomMargin:CGFloat = 20.0
let sceneHeight = UIScreen.mainScreen().bounds.height
let topDistance = sceneHeight - stackView.frame.height - bottomMargin
let metric = ["topDistance": topDistance, "bottomMargin": 20.0]
let views = ["stackView": stackView, "orangeView": orangeView]
NSLayoutConstraint.activateConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-topDistance-[stackView]-bottomMargin-[orangeView]-bottomMargin-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: metric, views: views))
}
因此,无论您使用的iPhone尺寸如何,堆栈视图都始终布置在场景底部,离底部20个点,并且您可以向下滚动以查看橙色视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.