【发布时间】:2015-06-04 08:13:19
【问题描述】:
我想要一个动画将 UIImageView 移动到由一组新约束定义的新位置,但由于某种原因,我无法让它工作。我正在尝试:
@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
标签: ios swift autolayout constraints