Swift - 通过设置视图的transform属性实现动画
设置视图对象的transform属性,可以实现各种动画效果。
1,移动
指在同一平面内,将控件按照某个直线方向平移一定的距离。
|
1
2
3
4
5
|
//每次都从当前位置平移self.imageView.transform = CGAffineTransformTranslate(self.imageView.transform, -2.1, -2.1)//每次都从最开始的位置计算平移self.imageView.transform = CGAffineTransformMakeTranslation(2.3, 2.3) |
2,旋转
|
1
2
3
4
5
6
7
8
|
//连续旋转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,缩放
|
1
2
3
4
5
6
7
8
|
//连续缩放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,反转
|
1
2
3
4
5
6
7
8
9
10
11
12
|
//返回初始状态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) |
文章来自:http://www.cnblogs.com/Free-Thinker/p/4843438.html