仿射变换transform



- (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(100, 100, 50, 50)];

    rectView.backgroundColor = [UIColor greenColor];

    self.rectView = rectView;

    [self.view addSubview:rectView];

    

}



- (void)clickMeAction

{

//    1、仿射变换移动

//    (block动画从6.几开始出现)

    [UIView animateWithDuration:1 animations:^{

//        方法一:相对于最初的位置

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

        

//        方法二:相对于变化后的位置:self.rectView.transform

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

    }];

   

    //    2、仿射变换比例

    [UIView animateWithDuration:1 animations:^{

//        方法一

//        self.rectView.transform = CGAffineTransformMakeScale(2, 2);//中心点不变

//        方法二

//        self.rectView.transform = CGAffineTransformScale(self.rectView.transform, 2, 2);

        

    }];

    

    

    //    3、仿射变换旋转

    [UIView animateWithDuration:1 animations:^{

//        方法一

//        self.rectView.transform = CGAffineTransformMakeRotation(M_PI_4);

//        方法二

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

        

//        度数变弧度

//        49/180.0*M_PI

        

    }];

    


//    4、三种变换的结合

//    1TranslationScalescale变换的时候,会影响Translation的变化,所以移动的变化使用frame或者center

//    [UIView animateWithDuration:1 animations:^{

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

//        CGRect frame = self.rectView.frame;

//        frame.origin.x += 50;

//        frame.origin.y += 50;

//        self.rectView.frame = frame;

//     }];

    

//    或者,动画分开

//    [UIView animateWithDuration:1 animations:^{

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

//    }];

//    

//    [UIView animateWithDuration:1 animations:^{

//        CGRect frame = self.rectView.frame;

//        frame.origin.x += 50;

//        frame.origin.y += 50;

//        self.rectView.frame = frame;

//    }];

    

    

    

    

//    2TranslationRotaterotate的变换会影响 锚点 的位置(锚点不会随着旋转而变化),所以移动使用center。使用frametransform 都有问题)

//    [UIView animateWithDuration:1 animations:^{

//        CGPoint point = self.rectView.center;

//        point.x += 50;

//        point.y += 50;

//        self.rectView.center = point;

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

//    }];

    

    

    

//    3ScaleRotate(完美搭配)

    [UIView animateWithDuration:1 animations:^{

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

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

    }];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值