【发布时间】:2020-01-23 07:25:41
【问题描述】:
我正在做 iWatch 应用程序。其中,用户必须步行 6 分钟。在那,我正在展示计时器。据此,我必须更改行走图像。我更改了 8 张图片。 如image1.png、image2.png等到image8.png
如何根据时长改变图像。
我是 Swift 语言的新手。
@IBOutlet weak var walkingImage: WKInterfaceImage!
let walkingImagesArray = ["walking1.png", "walking2.png", "walking3.png","walking4.png", "walking5.png","walking6.png", "walking7.png", "walking8.png"]
override func awake(withContext context: Any?) {
super.awake(withContext: context)
self.startTimer()
}
func startTimer() {
self.countdownTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.updateTime), userInfo: nil, repeats: true)
}
@objc func updateTime() {
count = count + 1
if(count < 361) {
timerLabel.setText(String(timeString(time: TimeInterval(count))))
//here I have to use switch case to change image
} else {
print("Workout completed")
countdownTimer.invalidate()
session.end()
builder.endCollection(withEnd: Date()) { (success, error) in
self.builder.finishWorkout { (workout, error) in
DispatchQueue.main.async() {
self.session = nil
self.builder = nil
}
}
}
}
print("\(count)")
}
有什么建议吗?
【问题讨论】:
-
每4分钟,我要更新图像,我已经给了updateTIme代码@Anbu.Karthik
-
@AnilkumariOSReactNative- bro,你能显示你创建的updateTime吗,如果你的时间间隔是
-
@Anbu.Karthik 已更新
标签: ios swift xcode apple-watch progress