【发布时间】:2015-09-08 16:33:54
【问题描述】:
我将我的代码从 Swift 1.2 迁移到 Swift 2.0
在 Swift 1.2/ iOS8 中,动画可以正常工作。但在 iOS 9 中,它不会对其进行动画处理,Label 会立即更改位置,就好像从未调用过 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 不可动画?
【问题讨论】:
标签: ios uiview swift2 ios9 xcode7