Swift-animate by setting the Transform property of the view

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.