gpt4 book ai didi

swift - UIlabel 动画不适合屏幕

转载 作者:行者123 更新时间:2023-11-28 16:01:31 24 4
gpt4 key购买 nike

这是一个问答应用程序,在回答问题后,下一个问题会在屏幕上动画显示。问题是,如果下一个问题是一个较长的问题,它就会越过屏幕。我将标签设置为 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()

})
}

最佳答案

您可以尝试将其放入您的layoutSubviews 方法

self.currentQuestionLabel.preferredMaxLayoutWidth = self.view.frame.width

关于swift - UIlabel 动画不适合屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41000546/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com