IOS中的关键帧动画

来源:互联网 发布:淘宝特步鞋 编辑:程序博客网 时间:2024/05/22 12:09

关键帧动画可以使你完成flash一样的分步的动画。

//设置一个关键帧动画,总时间,延迟时间等UIView.animateKeyframesWithDuration(5.0, delay: 1, options: UIViewKeyframeAnimationOptions.LayoutSubviews, animations: { () -> Void in//接下来加入一个一个的关键帧即可,这里要注意,起始时间和持续时间都是之前设置的总时间的百分比     UIView.addKeyframeWithRelativeStartTime(0.0, relativeDuration: 0.2, animations: { () -> Void in         self.redBlock?.backgroundColor = UIColor.blackColor()     })     UIView.addKeyframeWithRelativeStartTime(0.2, relativeDuration: 0.2, animations: { () -> Void in         self.redBlock?.center = self.view.center     })     UIView.addKeyframeWithRelativeStartTime(0.4, relativeDuration: 0.6, animations: { () -> Void in         let rotation = CGFloat(270 * M_PI / 180.0)         self.redBlock?.transform = CGAffineTransformMakeRotation(rotation)     })     }) { (Bool) -> Void in         //在动画全部结束时要做的事         self.redBlock?.backgroundColor = UIColor.blueColor() }
0 0
原创粉丝点击