码迷,mamicode.com
首页 > Web开发 > 详细

仿射变换(CGAffineTransform)使用小结

时间:2016-01-30 18:14:58      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

一、理论基础

请参考CGAffineTransform简单分析

二、效果演示

技术分享

三、实现代码

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下载地址

github下载地址 

 

转自:http://blog.csdn.net/yixiangboy 

仿射变换(CGAffineTransform)使用小结

标签:

原文地址:http://www.cnblogs.com/sungk/p/5171083.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!