gpt4 book ai didi

ios - 我如何继续旋转图像,直到服务器快速响应

转载 作者:行者123 更新时间:2023-11-30 11:05:00 33 4
gpt4 key购买 nike

每当单击按钮时,我都会进行异步调用,现在我想要一个像刷新图标一样的图像旋转或旋转,直到我收到服务器的响应。我现在所拥有的只是将 pi 旋转 180,并且当响应到达时图像也不会重置。下面粘贴了我的示例代码:

//When the update button is clicked
@objc func updateHome(){
UIView.animate(withDuration: 1) {
self.updateIcon.transform = CGAffineTransform(rotationAngle: .pi)
}
getBalances()
}
//Inside getBalances function
DispatchQueue.main.async {
if responseCode == 0 {
let today = self.getTodayString()
print("Time: \(today)")
UIView.animate(withDuration: 1) {
self.updateIcon.transform = CGAffineTransform(rotationAngle: .pi)
}
}

最佳答案

此代码使用 CABasicAnimation 无限期地旋转您的 UIImageView:

let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = CGFloat(.pi * 2.0)
rotateAnimation.duration = 1.0 // Change this to change how many seconds a rotation takes
rotateAnimation.repeatCount = Float.greatestFiniteMagnitude

updateIcon.layer.add(rotateAnimation, forKey: "rotate")

当您从服务器收到信号时,您可以调用

updateIcon.layer.removeAnimation(forKey: "rotate")

停止动画

关于ios - 我如何继续旋转图像,直到服务器快速响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52822778/

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