[英]UIView origin is not equal to zero
I setup a view controller scene with interface builder. 我使用界面构建器设置了一个视图控制器场景。 I add a view to my controller and add a custom class (CustomView) to it. 我将视图添加到控制器,并向其添加自定义类(CustomView)。
The view controller code 视图控制器代码
class ViewController: UIViewController {
@IBOutlet var myCustomView: CustomView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
print(myCustomView.frame.origin)
}
}
The question 问题
Why the origin of myCustomView
is equal to (-4.0, 64.0) and not (0, 64) ? 为什么myCustomView
的原点等于(-4.0,64.0)而不是(0,64)?
when you add the constraints,your constraints to margin remains unchecked. 当您添加约束时,您对边距的约束将保持未选中状态。 Because of constraints to margin
it gives you a frame that starts with (-4.0,64.0) like that... 由于页constraints to margin
的constraints to margin
它为您提供以(-4.0,64.0)开头的框架,如下所示...
Try to pinned all your edges without constraints to margin that will solve your problem .. 尝试将所有边缘固定在没有限制的边缘,这将解决您的问题..
For more guide about constraints to margin, check this link 有关边距约束的更多指南,请查看此链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.