Do not fight the restrictions set in the storyboard. Instead, you can create a constraint @IBOutlet
to a height constraint by finding it in the "Document Structure" controlview and separating it from your constraint to your code. Give him a name like tableHeightContraint
.
@IBOutlet weak var tableHeightConstraint: NSLayoutConstraint!
Then, when you want to change the height UITableView
, change the constant
restriction property :
tableHeightConstraint.constant = scrollView.frame.height - 30
As @BlackRider noted in the comments, sometimes you need to call the layout after the restrictions have been changed.
Vocation:
view.layoutIfNeeded()
will tell Auto Layout to apply the constraint if necessary. This is especially true if you are reviving change. In this case, the call layoutIfNeeded()
is made inside the animation block.
UIView.animateWithDuration(2) {
self.view.layoutIfNeeded()
}
source
share