Jay*_*iyk 5 uiview ios ios9 xcode7 swift2
我将我的代码从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);
Run Code Online (Sandbox Code Playgroud)
使用UIBUTTON(IT WORKS)
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);
Run Code Online (Sandbox Code Playgroud)
但是如果我在UIButton上做同样的事情,那就行了!
有什么想法吗?为什么UILabel不可动画?
尝试添加:
self.titleLabel.setNeedsLayout();
Run Code Online (Sandbox Code Playgroud)
在动画块之前.
| 归档时间: |
|
| 查看次数: |
1609 次 |
| 最近记录: |