watchOS 2 does not have any kind of completion block in its animateWithDuration function. I'm working on a game that requires running code after an animation is completed. Are there any work arounds? Perhaps using key-value observation? The alternative would be to use a timer that matches up with the length of the animation but that's non-ideal for obvious reasons.
NSOperation didn't work for me too. I am just using the following solution for now until Apple officially adds a completion block. Not ideal but it works. I have opened a Radar. Maybe Apple would add a completion block in a future seed of watchOS 2.
This extension adds an animateWithDuration method that takes a completion block. And the completion block is called after the duration of the animation block.
extension WKInterfaceController {
func animateWithDuration(duration: NSTimeInterval, animations: () -> Void, completion: (() -> Void)?) {
animateWithDuration(duration, animations: animations)
let completionDelay = dispatch_time(DISPATCH_TIME_NOW, Int64(duration * Double(NSEC_PER_SEC)))
dispatch_after(completionDelay, dispatch_get_main_queue()) {
completion?()
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With