1,cakeyframeanimation Introduction
Cakeyframeanimation can implement key-frame animations, which can be used to animate a property according to a string of values, as if it were a frame-by-frame production.
2, using the sample (set five key coordinates, the picture is moved by key points in turn)
123456789101112131415161718192021 |
let animation =
CAKeyframeAnimation
(keyPath:
"position"
)
//设置5个位置点
let p1 =
CGPointMake
(0.0, 0.0)
let p2 =
CGPointMake
(300, 0.0)
let p3 =
CGPointMake
(0.0, 400)
let p4 =
CGPointMake
(300, 400)
let p5 =
CGPointMake
(150, 200)
//赋值
animation.values = [
NSValue
(
CGPoint
: p1),
NSValue
(
CGPoint
: p2),
NSValue
(
CGPoint
: p3),
NSValue
(
CGPoint
: p4),
NSValue
(
CGPoint
: p5)]
//每个动作的时间百分比
animation.keyTimes = [
NSNumber
(float: 0.0),
NSNumber
(float: 0.4),
NSNumber
(float: 0.6),
NSNumber
(float: 0.8),
NSNumber
(float: 1.0), ]
animation.delegate =
self
animation.duration = 6.0
self
.imageView.layer.addAnimation(animation, forKey:
"Image-Move"
)
|
3, you can set the animation agent, listen to start and end action
123456789 |
animation.delegate =
self
override func animationDidStart(anim:
CAAnimation
!) {
println
(
"动画开始"
)
}
override func animationDidStop(anim:
CAAnimation
!, finished flag:
Bool
) {
println
(
"动画结束"
)
}
|
Swift-use cakeyframeanimation for keyframe animations