连续动画-Watchkit



我希望为apple watch应用程序提供各种动画。我使用了一系列图像,动画的方法是启动AnimationingWithImagesInRange()。每当我有连续的动画指令时,只有代码中的最后一个指令会执行。代码看起来像:

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-请随时为我的小框架提供一些反馈。:)

手表不会为您排队播放动画,因此请使用延迟等于第一个动画持续时间的NSTimer,并在计时器启动后启动第二个动画。

最新更新