这是我的代码,跳过按钮动画不起作用。它立刻就消失了。 它就消失了
skipButtonBottomConstraint.constant = -40
UIView.animate(withDuration: 1.0, animations: {
self.titleLabel.alpha = 0
self.skipButton.alpha = 0
self.pageControl.alpha = 0
self.view.setNeedsLayout()
})
你可以解释一下原因吗?
答案 0 :(得分:2)
我认为Paul是对的,你应该在动画块中调用layoutIfNeeded()
,而不是setNeedsLayout()
答案 1 :(得分:-2)
确保在layoutIfNeeded
setNeedsLayout
同样Apple建议 - 在动画块之前调用一次,以确保所有待处理的布局操作都已完成。
self.view.layoutIfNeeded()
self.skipButtonBottomConstraint.constant = -40
UIView.animate(withDuration: 1.0, animations: {
self.titleLabel.alpha = 0
self.skipButton.alpha = 0
self.pageControl.alpha = 0
self.view.layoutIfNeeded()
})