【发布时间】:2016-12-06 16:45:19
【问题描述】:
这是一个测验应用程序,它会提出问题,回答完下一个问题后会在屏幕上显示动画。问题是,如果下一个问题是一个较长的问题,它将超出屏幕。我将标签设置为 2 行。
func animateLabelTransitions(){
// Animate the alpha
// and the center X constraints
let screenWidth = view.frame.width
self.nextQuestionLabelCenterXConstraint.constant = 0
self.currentQuestionCenterXConstraint.constant += screenWidth
UIView.animate(withDuration: 0.5,
delay: 0,
options: [],
animations: {
self.currentQuestionLabel.alpha = 0
self.nextQuestionLabel.alpha = 1
self.view.layoutIfNeeded()
},
completion: { _ in
swap(&self.currentQuestionLabel,
&self.nextQuestionLabel)
swap(&self.currentQuestionCenterXConstraint,
&self.nextQuestionLabelCenterXConstraint)
self.updateOffScreenLabel()
})
}
【问题讨论】: