Set the Transform property of the View object to achieve a variety of animation effects.
1, moveIn the same plane, the control translates a certain distance in a straight line direction.
12345 |
//每次都从当前位置平移 self .imageView.transform = CGAffineTransformTranslate ( self .imageView.transform, -2.1, -2.1) //每次都从最开始的位置计算平移 self .imageView.transform = CGAffineTransformMakeTranslation (2.3, 2.3) |
2, rotate
12345678 |
//连续旋转
UIView
.beginAnimations(
nil
, context:
nil
)
UIView
.setAnimationDuration(3.0)
//设置动画时间
self
.imageView.transform =
CGAffineTransformRotate
(
self
.imageView.transform,
CGFloat
(-
M_PI
/2))
UIView
.commitAnimations()
//独立旋转,以初始位置旋转
self
.imageView.transform =
CGAffineTransformMakeRotation
(
CGFloat
(-
M_PI
/4))
|
3, Zoom
12345678 |
//连续缩放
UIView
.beginAnimations(
nil
, context:
nil
)
UIView
.setAnimationDuration(3.0)
//设置动画时间
self
.imageView.transform =
CGAffineTransformScale
(
self
.imageView.transform, 1.5 ,1.5)
UIView
.commitAnimations()
//独立缩放,以初始位置缩放
self
.imageView.transform =
CGAffineTransformMakeScale
(1.3, 1.3)
|
4, Reverse
123456789101112 |
//返回初始状态
self
.imageView.transform =
CGAffineTransformIdentity
//连续反转
UIView
.beginAnimations(
nil
, context:
nil
)
UIView
.setAnimationDuration(3.0)
//设置动画时间
self
.imageView.transform =
CGAffineTransformConcat
(
self
.imageView.transform,
CGAffineTransformInvert
(
self
.imageView.transform))
UIView
.commitAnimations()
//独立反转,以初始位置反转
self
.imageView.transform =
CGAffineTransformInvert
(
self
.imageView.transform)
|
Swift-Animate by setting the Transform property for a view