iOS Keyframe animation 怎么对计数响应


UIView.animateKeyframesWithDuration(5, delay: 0, options: [UIViewKeyframeAnimationOptions.Repeat], animations: {
        UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 0.3, animations: {
            self.imageView!.center.x = self.view.bounds.width / 2
        })
        }, completion: nil)

}

比如上面这段代码 ,重复执行动画,每次执行完之后都比如说执行print("hello")
要怎么操作
求大神解答

阅读 2.6k
2 个回答

动画闭包内的内容会在每次执行的时候触发


UIView.animateKeyframesWithDuration(5, delay: 0, options: [UIViewKeyframeAnimationOptions.Repeat], animations: {
        //执行这个关键帧动画时打印hello
        print("hello")
        UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 0.3, animations: {
            self.imageView!.center.x = self.view.bounds.width / 2
            //执行这一帧的时打印hello
            print("hello")
        })
        }, completion: nil)

}

好像不可以也试一下其他方法吧,要不用延时来调吧
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

    //            // 1秒后异步执行

});

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题