【问题标题】:UIlabel animation won't fit in the screenUIlabel 动画不适合屏幕
【发布时间】: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()

                                    })
}

【问题讨论】:

    标签: swift xcode animation


    【解决方案1】:

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

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

    【讨论】:

    猜你喜欢
    • 2016-12-11
    • 1970-01-01
    • 2011-02-16
    • 2016-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2018-02-11
    相关资源
    最近更新 更多