gpt4 book ai didi

ios - 变换标签字体大小

转载 作者:行者123 更新时间:2023-12-01 16:06:11 26 4
gpt4 key购买 nike

我有两个捷径。
它们每个都有初始属性,例如字体大小和不透明度。
在动画之前,值是

labelOne.font = labelOne.font.withSize(109)
labelOne.alpha = 1.0

labelTwo.font = labelTwo.font.withSize(40)
labelTwo.alpha = 0.7

在动画之后,它们应该具有以下属性:
labelOne.font = labelOne.font.withSize(40)
labelOne.alpha = 0.7

labelTwo.font = labelTwo.font.withSize(109)
labelTwo.alpha = 1.0

对于转换,我使用 CGAffineTransform() 例子:
labelOne.transform = CGAffineTransform(scaleX: //some value? , y: //someValue?)

但我是编程新手,不太了解它是如何工作的。告诉我如何用调整字体大小来编写这个动画?

最佳答案

要在两个标签上实现动画,如您希望通过控制字体大小和 alpha 来实现,您可以这样实现:

// Before animation
labelOne.font = labelOne.font.withSize(109)
labelOne.alpha = 1.0

labelTwo.font = labelTwo.font.withSize(40)
labelTwo.alpha = 0.7
UIView.animate(withDuration: 1, animations: {
// This will be values set during the animation of 1 second
self.labelOne.font = labelOne.font.withSize(40)
self.labelOne.alpha = 0.7

self.labelTwo.font = labelTwo.font.withSize(109)
self.labelTwo.alpha = 1.0
})

同时, CGAffineTransform(scaleX:, y:)允许您缩放 View 的 X、Y 坐标值(例如 labelOne),但要通过动画实现这一点,您必须将其放在 animate 块中:
// normal state
labelOne.transform = CGAffineTransform(scaleX: 1, y: 1)
labelTwo.transform = CGAffineTransform(scaleX: 0.7, y: 0.7)
UIView.animate(withDuration: 1, animations: {
// State reached through the animation
labelOne.transform = CGAffineTransform(scaleX: 0.7, y: 0.7)
labelTwo.transform = CGAffineTransform(scaleX: 1, y: 1)
})

要实现更平滑的过渡,请使用:
UIView.transition(with: labelOne, duration: 0.25, options: .transitionCrossDissolve, animations: {
self.labelOne.font = UIFont.systemFont(ofSize: 40)
}) { _ in }

关于ios - 变换标签字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60005497/

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