我想要一個動畫來將UIImageView移動到由一組新約束定義的新位置,但出於某種原因,我無法使其工作。我試圖做:使用Swift更新動畫中的約束條件
@IBOutlet weak var oldBottom: NSLayoutConstraint!
...
func animateMovement() {
// Here I'm defining a new constraint
var newBottom = NSLayoutConstraint(
item: self.logo,
attribute: NSLayoutAttribute.Bottom,
relatedBy: NSLayoutRelation.Equal,
toItem: self.usernameField,
attribute: NSLayoutAttribute.Bottom,
multiplier: 1,
constant: 15)
self.view.layoutIfNeeded()
UIView.animateWithDuration(1.0, animations: {
// Here I'm setting the already existing constraint (defined in storyboard) to the new constraint
self.oldBottom = newBottom
self.view.layoutIfNeeded()
}, completion: {})
}
任何想法將不勝感激!
輸入別叫layoutIfNeeded動畫塊 – mustafa