我目前正在尝试访问我之前为其设置锚点的视图的高度。因此,例如,我searchTable
在 ViewController 中设置了使用以下内容的左、右、上和下锚:
searchTable.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
searchTable.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
searchTable.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
searchTable.bottomAnchor.constraint(equalTo: menuBar.topAnchor).isActive = true
searchTable
是我创建的一个类的对象,它继承自 UIView 并在其中有一个 UIImageView。我通过在 init 函数中使用以下内容来约束 UIImageView:
imageView.topAnchor.constraint(equalTo: topContainer.topAnchor, constant: 10).isActive = true
imageView.leftAnchor.constraint(equalTo: topContainer.leftAnchor, constant: 10).isActive = true
imageView.heightAnchor.constraint(equalTo: self.heightAnchor, multiplier: topContainerMultiplier * imageProfileMultiplier).isActive = true
imageView.widthAnchor.constraint(equalTo: self.heightAnchor, multiplier: topContainerMultiplier * imageProfileMultiplier).isActive = true
在哪里:
let topContainerMultipler: Double = 1 / 7
let imageProfileMultipler: Double = 1 / 5
在 init 的 init 函数中searchTable
,我尝试将角半径设置为图像大小的一半。我尝试使用self.frame.height
,self.frame.size.height
和self.bounds.height
获取约束的.constant
值,但都返回 0。self.heightAnchor
我认为有一个解决方案来解决这个问题,但我一直无法找到它。