swift - iOS Keyframe animation 怎么对计数响应
天蓬老师
天蓬老师 2017-04-17 17:57:08
[iOS讨论组]

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)
迷茫

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


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秒后异步执行

});

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号