animateWithDuration缺少完成块,WatchOS 2 [英] animateWithDuration lacks completion block, WatchOS 2

查看:73
本文介绍了animateWithDuration缺少完成块,WatchOS 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

watchOS 2的animateWithDuration函数中没有任何类型的完成块.我正在开发一个需要在动画完成后运行代码的游戏.有什么解决方法吗?也许使用键值观察?另一种选择是使用与动画长度匹配的计时器,但是出于明显的原因,这是不理想的.

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对我也不起作用.在Apple正式添加完成模块之前,我现在仅使用以下解决方案.不理想,但可以.我打开了雷达.也许苹果会在watchOS 2的未来种子中添加一个完成块.

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.

此扩展添加了一个带有完成块的animateWithDuration方法.然后在动画块的持续时间之后调用完成块.

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?()
        }
    }
}

这篇关于animateWithDuration缺少完成块,WatchOS 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆