关于这个问题,我真的需要您的帮助。我正在以编程方式创建UIView对象,而没有在开始时设置边界。创建后,我向该视图添加了约束以适合屏幕中所需的位置。
但是问题是,我想在代码的以下部分中使用该UIView的bounds属性,但是不幸的是,在设置了屏幕上显示的约束之后,我无法获得边界。
下面我有示例代码:
let previewView = UIView()
NSLayoutConstraint(item: previewView, attribute: .top, relatedBy: .equal, toItem: upperView, attribute: .bottom, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: previewView, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottom, multiplier: 1.0, constant: 0.0).isActive = true
previewView.widthAnchor.constraint(equalToConstant: self.view.frame.width).isActive = true
previewView.translatesAutoresizingMaskIntoConstraints = false
print(previewView.bounds)
// (0.0, 0.0, 0.0, 0.0) ->>>> How can I get the bounds as it shows on the screen instead of 0,0,0,0
在这一点之后,当我尝试使用previewView.bounds属性时,它将返回其原始大小为0。
如何获得包含相关容器设置的屏幕上显示的边界?
非常感谢你们。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句