UILabel降低高度,自动布局怪异动画

时间:2015-10-26 15:25:19

标签: ios animation autolayout uilabel

我有可扩展的UILabel:

func expandDescriptionLabel() {
    let calculatedHeightDescriptionLabel = lblDescription.sizeThatFits(CGSizeMake(lblDescription.frame.width, CGFloat.max)).height
    expanded = true
    UIView.animateWithDuration(0.3, animations: {
        self.cnsDescriptionHeight.constant = calculatedHeightDescriptionLabel
        self.hideMoreButton()// this line means nothing, results are the same with this line commented out
        self.view.layoutIfNeeded()
    })

}

func reduceDescriptionLabel() {
    expanded = false
    self.cnsDescriptionHeight.constant = 60
    UIView.animateWithDuration(0.3, animations: {
        self.showMoreButton() // this line means nothing, results are the same with this line commented out
        self.lblDescription.setNeedsLayout();
        self.view.layoutIfNeeded()
    })
}

当扩展动画看起来很好,但是当高度在下降时会发生奇怪的事情。看下面的GIF。我已经尝试CGAffineTransformScale并将UILabel放入UIView中,然后为UIView设置动画。

问题是如何使动画的最后部分更加流畅。 正如您所看到的,当标签高度降低时,文本会向上移动然后突然出现在正确的位置(没有动画)。

enter image description here

0 个答案:

没有答案