5
的动画我迁移我的代码从雨燕1.2至2.0雨燕的iOS 9故障的UILabel
在雨燕1.2/iOS8上,动画只是工作。但是在iOS 9中,它并没有对它进行动画处理,标签立即改变位置,就好像从未调用过layoutIfNeeded
一样。
这是我如何为我的UILabel制作一个UIButton的动画。 (我用的自动布局,这就是为什么我用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(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);
但是如果我在UIButton上做同样的工作!
有什么想法?为什么UILabel不具有动画性?
它解决了它。但为什么? – JayVDiyk
通常,当您更新视图上的约束时,应让iOS布局系统通过使用setNeedsLayout方法知道约束已更改。这是苹果的性能优化,因此他们不会尝试不必要地布置视图。至于为什么它适用于UIButton,我不能肯定地说。 Apple可能会在UIButton实现中调用setNeedsLayout。 –
谢谢。这解决了它。这只发生在iOS9中。 – JayVDiyk