watchkit - animateWithDuration lacks completion block, WatchOS 2 -
watchos 2 not have kind of completion block in animatewithduration function. i'm working on game requires running code after animation completed. there work arounds? perhaps using key-value observation? alternative use timer matches length of animation that's non-ideal obvious reasons.
nsoperation didn't work me too. using following solution until apple officially adds completion block. not ideal works. have opened radar. maybe apple add completion block in future seed of watchos 2.
this extension adds animatewithduration method takes completion block. , completion block called after duration of 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?() } } }
Comments
Post a Comment