我希望为 Apple Watch 应用程序提供各种动画。我正在使用一系列图像,动画方法是 startAnimatingWithImagesInRange()。每当我有连续的动画指令时,代码中只会执行最后一个指令。代码如下:
myImage.setImageNamed("testImage")
myImage.startAnimatingWithImagesInRange(NSRange(location: 0, length: 90), duration: 3, repeatCount: 1)
myImage.startAnimatingWithImagesInRange(NSRange(location: 90, length: 180), duration: 3, repeatCount: 1)
在上面的代码中,只有第二个动画会播放。我什至尝试将它们放在不同的函数中,所以我会单独调用每个函数,但它仍然只会播放我代码中的最后一个动画。我对此还很陌生,所以我确信有更好的方法,但经过数小时的研究后,我无法提出解决方案或在网上找到解决方案。
最佳答案
这就像 1 + 1 一样简单:)
这是你想要的:
myImage.setImageNamed("testImage")
let duration = 3
let repeatCount = 1
Timeline.with(identifier: "MyQueuedAnimation", delay: 0.0, duration: duration * repeatCount, execution: {
myImage.startAnimatingWithImagesInRange(NSRange(location: 0, length: 90), duration: duration, repeatCount: repeatCount)
}, completion: {
myImage.startAnimatingWithImagesInRange(NSRange(location: 90, length: 180), duration: duration, repeatCount: 1)
}).start
TimelineKit - 请随时给我一些关于我的小框架的反馈。 :)
关于ios - 连续动画 - Watchkit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29200549/