trying to animate a constraint in swift

后端 未结 6 1948
离开以前
离开以前 2020-11-29 16:00

I have a UITextField that I want to enlarge its width when tapped on. I set up the constraints and made sure the constraint on the left has the lower priority t

6条回答
  •  野性不改
    2020-11-29 16:23

    SWIFT 4.x :

    self.mConstraint.constant = 100.0
    UIView.animate(withDuration: 0.3) {
            self.view.layoutIfNeeded()
    }
    

    Example with completion:

    self.mConstraint.constant = 100
    UIView.animate(withDuration: 0.3, animations: {
            self.view.layoutIfNeeded()
        }, completion: {res in
            //Do something
    })
    

提交回复
热议问题