我面临的一个问题与autolayouts有关。我设置高度的看法包含图像意见为零第一次通过自动布局。但是如果调用了某个函数,我希望将高度更新为常量值,但视图的高度没有更新。下面是代码,我已经在函数中以编程方式更新了高度,但它不起作用。
let heightContraint = NSLayoutConstraint(item: businessImageView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 40)
businessImageView.addConstraint(heightContraint)
5条答案
按热度按时间biswetbf1#
首先创建高度约束的IBOutlet。
您只需要更改约束的
constant
属性。例如:将
self.view
替换为要更改高度的视图的父视图。ev7lccsx2#
创建约束出口,然后按如下方式设置:
tkqqtvp13#
businessImageView.addConstraint(heightContraint)
不是更新约束的代码。它添加了约束。为了更新父视图(包含图像)的高度,您需要更新businessImageView的height约束的常量。
xmd2e60i4#
方法
代码
xdnvmnnf5#
//让我们检测屏幕的高度
[bounds.size.width;