I have a UIImage
in code that I would like to enlarge vertically when a button is pressed. The UIImage
is fully constrained in the storyboard and I wou
You should to call layoutIfNeeded
within the animation block. Apple actually recommends you call it once before the animation block to ensure that all pending layout operations have been completed. I just checked it with the resizing of button - everything works fine.
@IBOutlet weak var myBtn: UIButton!
@IBOutlet weak var btnHeight: NSLayoutConstraint!
@IBOutlet weak var btnWidth: NSLayoutConstraint!
@IBAction func resizeBtn(sender: AnyObject) {
self.myBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0)
self.view.layoutIfNeeded()
self.btnHeight.constant += 50
self.btnWidth.constant += 50
UIView.animateWithDuration(0.7, animations: {
self.view.layoutIfNeeded()
})
}
P.S. make sure that other constraints don't block your changes.