watchOS 2 の animateWithDuration 関数には、いかなる種類の完了ブロックもありません。アニメーションの完了後にコードを実行する必要があるゲームに取り組んでいます。回避策はありますか? おそらくキー値の観察を使用していますか?別の方法として、アニメーションの長さと一致するタイマーを使用することもできますが、これは明らかな理由から理想的ではありません。
1244 次
4 に答える
6
NSOperation もうまくいきませんでした。Appleが正式に完了ブロックを追加するまで、私は今のところ次のソリューションを使用しています。理想的ではありませんが、うまくいきます。レーダーを開きました。Apple は、watchOS 2 の将来のシードに完了ブロックを追加するかもしれません。
この拡張機能は、完了ブロックを受け取る animateWithDuration メソッドを追加します。完了ブロックは、アニメーション ブロックの継続時間後に呼び出されます。
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?()
}
}
}
于 2015-06-21T02:58:41.697 に答える
2
WKInterfaceControllerで完了ブロックを使用してanimateWithDurationメソッドを拡張してみてください
Obj-C バージョン (@PunnetSethi に感謝):
- (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(void))completion{
[self animateWithDuration:duration animations:animations];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), completion);
}
WatchOS2で本物のWatchに取り組む
于 2015-10-05T20:27:36.753 に答える