一、理论基础
请参考 CGAffineTransform简单分析
Demo下载地址:私信回复“06”
二、效果演示
三、实现代码
3.1:位移变换
-(void)positionAnimation{ _DemoView.transform = CGAffineTransformIdentity; [UIView animateWithDuration:1.0f animations:^{ _demoView.transform = CGAffineTransformMakeTranslation(100, 100); }]; }3.2:缩放变换
-(void)scaleAnimation{ _demoView.transform = CGAffineTransformIdentity; [UIView animateWithDuration:1.0f animations:^{ _demoView.transform = CGAffineTransformMakeScale(2, 2); }]; }3.3:旋转变换
-(void)rotateAnimation{ _demoView.transform = CGAffineTransformIdentity; [UIView animateWithDuration:1.0f animations:^{ _demoView.transform = CGAffineTransformMakeRotation(M_PI); }]; }3.4:组合变换
-(void)combinationAnimation{ //仿射变换的组合使用 _demoView.transform = CGAffineTransformIdentity; [UIView animateWithDuration:1.0f animations:^{ CGAffineTransform transform1 = CGAffineTransformMakeRotation(M_PI); CGAffineTransform transform2 = CGAffineTransformScale(transform1, 0.5, 0.5); _demoView.transform = CGAffineTransformTranslate(transform2, 100, 100); }]; }3.5:矩阵的反转
-(void)invertAnimation{ _demoView.transform = CGAffineTransformIdentity; [UIView animateWithDuration:1.0f animations:^{ //矩阵反转 _demoView.transform = CGAffineTransformInvert(CGAffineTransformMakeScale(2, 2)); }]; }四、补充
- CGAffineTransformIdentity : 单位矩阵变换,一般用于仿射变换的初始化或者还原。
- CGAffineTransformEqualToTransform(CGAffineTransform t1,
- CGAffineTransform t2) : 判断两个变换矩阵是否相等
- CGAffineTransformConcat(CGAffineTransform t1,
- CGAffineTransform t2) : 得到两个矩阵相加后得到的最终矩阵
- CGPoint CGPointApplyAffineTransform(CGPoint point,
- CGAffineTransform t) : 某点通过矩阵变换之后的点
- CGSize CGSizeApplyAffineTransform(CGSize size, CGAffineTransform t) : 某个size通过矩阵变换之后的size
- CGRect CGRectApplyAffineTransform(CGRect rect, CGAffineTransform t) : 某个Rect通过矩阵变换之后的区域
五、Demo下载地址
Demo下载地址:私信回复“06”
如果觉得对你还有些用,就关注小编+转发这一篇文章。你的支持是我继续的动力。
下篇文章预告:UICollectionView初步入门
文章来源于网络,如有侵权,请联系小编删除。
1.《ios如何修改cgrect》援引自互联网,旨在传递更多网络信息知识,仅代表作者本人观点,与本网站无关,侵删请联系页脚下方联系方式。
2.《ios如何修改cgrect》仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证。
3.文章转载时请保留本站内容来源地址,https://www.lu-xu.com/keji/3225546.html