我将我的代码从Swift 1.2迁移到了Swift 2.0。
在Swift 1.2/iOS8中,动画正常工作。但在iOS9中,它不会进行动画,标签会立即改变位置,就好像layoutIfNeeded
从未被调用过一样。
这是我如何使用UILabel和UIButton进行动画的方式。(我使用Autolayout,因此我使用layoutIfNeeded)
使用UILabel(不起作用)
titleLabelTopConstraint.constant = 88;
UIView.animateWithDuration(0.8, delay: 0.38, usingSpringWithDamping: 0.54, initialSpringVelocity: 1, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in
self.titleLabel.layoutIfNeeded();
}, completion: nil);
使用UIBUTTON(它有效)
buttonTopConstraint.constant = 88;
UIView.animateWithDuration(0.8, delay: 0.38, usingSpringWithDamping: 0.54, initialSpringVelocity: 1, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in
self.button.layoutIfNeeded();
}, completion: nil);
但是如果我在UIButton上执行同样的操作,它可以正常工作!
有什么想法吗?为什么UILabel不能被动画化?