仿射变换---位移+缩放比例+旋转

对于仿射变换的理解,以本人现阶段水平还谈不上是深入了解,我喜欢把它想象成一种简单的动画效果,下面介绍几种简单的变化:位置移动,按一定比例缩放,顺时针、逆时针旋转




#import "ViewController.h"


@interface ViewController ()


@property (nonatomic,weak) UIView * rectView;


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

   

    //"点我" 控制按钮

    UIButton * button=[UIButton buttonWithType:UIButtonTypeCustom];

    [button setTitle:@"点我" forState:UIControlStateNormal];

    button.frame=CGRectMake(self.view.frame.size.width-110, 20, 100, 44);

    button.backgroundColor=[UIColor redColor];

    //添加点击事件

    [button addTarget:self action:@selector(clickMeAction) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button];

    

    

    UIView * rectView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 150, 150)];

    rectView.center=self.view.center;

    rectView.backgroundColor=[UIColor greenColor];

    self.rectView=rectView;

    [self.view addSubview:rectView];

}


#pragma mark - clickAction

- (void) clickMeAction

{

//仿射变换移动

    //1.从当前位置,向右移动50,向下移动100   (直接变换)

    /*

    self.rectView.transform=CGAffineTransformMakeTranslation(50, 100);

    */

    

    

    //2.(方法一)从当前位置,向右移动50,向下移动100  0.5秒钟时延)

    /*

    [UIView animateWithDuration:0.5 animations:^{

        self.rectView.transform=CGAffineTransformMakeTranslation(50, 100);

    }];

    */

    

    

    //3.(方法二)从当前位置,向右移动50,向下移动100  0.5秒钟时延)

    /*

    [UIView animateWithDuration:0.5 animations:^{

        //self.rectView.transform=CGAffineTransformMakeTranslation(50, 100);

        self.rectView.transform=CGAffineTransformTranslate(self.rectView.transform, 100, 100);

    }];

    */

    

    

//仿射变换比例


    //1.中心点不变,宽度缩小为原来的0.1倍,高度缩短为原来的0.5

    /*

    [UIView animateWithDuration:0.5 animations:^{

        self.rectView.transform=CGAffineTransformMakeScale(0.1, 0.5);

    }];

    */

    

    //2.中心点不变,扩大为原来的5

    /*

    [UIView animateWithDuration:0.5 animations:^{

        self.rectView.transform=CGAffineTransformMakeScale(5, 5);

    }];

    */

    

    

    //3.(方法一)向右向下各移动100

    /*

    [UIView animateWithDuration:0.5 animations:^{

         self.rectView.transform=CGAffineTransformMakeTranslation(100, 100);

    }];

    */

    

    

    //4.(方法二)向右向下各移动100

    /*

    [UIView animateWithDuration:0.5 animations:^{

       self.rectView.transform=CGAffineTransformMakeTranslation(100, 100);

    }];

    */

    

    

    //5.在前一个位置的基础之上,向右向下分别移动1个距离

    /*

    [UIView animateWithDuration:0.5 animations:^{

        self.rectView.transform=CGAffineTransformTranslate(self.rectView.transform,1,1);

    }];

    */

    

    

    //6.在前一个位置的基础之上,向右向下分别移动100个距离

    /*

    [UIView animateWithDuration:0.5 animations:^{

        CGAffineTransform form=self.rectView.transform;

        self.rectView.transform=CGAffineTransformTranslate(form,100,100);

    }];

    */

    

    

    //7.来回弹跳切换着向右下角移动10个单位

    /*

    [UIView animateWithDuration:0.5 animations:^{

        CGAffineTransform form=self.rectView.transform;

        self.rectView.transform=CGAffineTransformMakeScale(2, 2);

        self.rectView.transform=CGAffineTransformTranslate(form,10,10);

    }];

    */

    

    

//仿射变换---旋转

    //1.顺时针旋转90

    /*

    [UIView animateWithDuration:0.5 animations:^{

        self.rectView.transform=CGAffineTransformMakeRotation(M_PI_2);

    }];

    */

    

    

    //2.在前一个位置的基础之上,顺时针旋转45

    /*

    [UIView animateWithDuration:0.5 animations:^{

        CGAffineTransform form=self.rectView.transform;


        self.rectView.transform=CGAffineTransformRotate(form,M_PI_4);

    }];

    */

    

    

    //3.在前一个位置的基础之上,逆时针旋转45

    /*

    [UIView animateWithDuration:0.5 animations:^{

        CGAffineTransform form=self.rectView.transform;

        

        self.rectView.transform=CGAffineTransformRotate(form,-M_PI_4);

    }];

    */

    

    

    //4.在前一个位置的基础之上,顺时针旋转确定的度数

    [UIView animateWithDuration:0.5 animations:^{

        CGAffineTransform form=self.rectView.transform;

        

        self.rectView.transform=CGAffineTransformRotate(form,9/100.0*M_PI);

    }];

 

}


@end







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值