6

假设我使用 CGAffineTransformScale 缩放 UILabel,如下所示:

let scale = 0.5
text = UILabel(frame: CGRectMake(100, 100, 100, 100))
text.text = "Test"

UIView.animateWithDuration(2.0, delay: 0.0, options: UIViewAnimationOptions.CurveEaseIn, animations: {
    self.text.transform = CGAffineTransformScale(self.text.transform, scale, scale)
}, completion: {(value : Bool) in
    print("Animation finished")
})

当我想将 UILabel 缩放一半时,这很有效。但是,如果我再次调用相同的代码,它会以 0.25 的比例结束,因为它再次缩放一半。

是否可以使用 CGAffineTransformScale 始终缩放到原始 UILabel 框架的一半大小,而不是累积缩放?

4

3 回答 3

15

斯威夫特 3

text.transform = CGAffineTransform.identity
UIView.animate(withDuration: 0.25, animations: {
   self.text.transform = CGAffineTransform(scaleX: scale, y: scale)
})
于 2016-11-04T23:24:36.213 回答
5

您正在缩放现有的变换。只需创建一个新的转换:

self.text.transform = CGAffineTransformMakeScale(scale, scale)
于 2016-04-21T22:04:36.140 回答
0

斯威夫特版本:

self.text.transform = CGAffineTransform.init(scaleX: scaleFactorX, y: scaleFactorY)
于 2021-04-09T14:27:05.797 回答