gpt4 book ai didi

swift - 将图像调整为初始大小

转载 作者:行者123 更新时间:2023-11-28 06:12:07 24 4
gpt4 key购买 nike

我正在使用 2 个动画。当屏幕启动时,第一个动画在 viewDidLoad 中开始。

此动画应用于名为 layer2layer3 的 2 个图像。

func firstAnimation(){
UIView.animate(withDuration: 1, delay: 0, options:
UIViewAnimationOptions.repeat , animations: {

self.layer2.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
self.layer3.transform = CGAffineTransform(scaleX: 2, y: 2)
}, completion: { finished in

})
}

当长按名为 layer0 的图像时,firstAnimation() 将被以下代码停止:

layer2.layer.removeAllAnimations()
layer3.layer.removeAllAnimations()

layer2layer3 应用了不同的动画。

第二个动画是

func secondAnimation() {
UIView.animate(withDuration: 20, delay: 0, options:
UIViewAnimationOptions.curveEaseOut , animations: {

self.layer2.transform = CGAffineTransform(scaleX: 10, y: 10)
self.layer3.transform = CGAffineTransform(scaleX: 10, y: 10)

}, completion: { finished in

})
}

当我想删除第二个动画并再次启动第一个动画时,2 个图像 layer2 和 layer3 从它们因第二个动画而获得的大小开始。如何使用图像的初始大小重新启动第一个动画?

最佳答案

您可以使用 CGAffineTransform.identity 重置已转换为原始比例的 View 。

例如:

layer2.transform = .identity

关于swift - 将图像调整为初始大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46240782/

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