IOS中UIView的transform(形变属性)

    UIView *temp = [[UIView alloc]init];
    temp.frame = CGRectMake(100, 100, 100, 100);
    temp.backgroundColor = [UIColor orangeColor];
    UISwitch *sw = [[UISwitch alloc]init];
    [temp addSubview:sw];
    [self.view addSubview:temp];
    self.tempView = temp;
// transform:形变属性,能完成的功能:平移、缩放、旋转
      [UIView animateWithDuration:1.0 animations:^{
//        //缩放
//        self.tempView.transform = CGAffineTransformMakeScale(0.5, 0.5);
//        //平移
//        self.tempView.transform = CGAffineTransformMakeTranslation(100, 100);
//        //旋转
//        self.tempView.transform = CGAffineTransformMakeRotation(M_PI_4);

        /**
         * 如果想通过设置transform属性同时完成平移、缩放、旋转综合操作需要一个已经完成形变的transform传给另一个完成二段形变的transform
            需要注意二段transform的创建不是make方法
         */
        //完成形变的transformA,把完成形变的transformA传给下一个transformB
        CGAffineTransform transformA = CGAffineTransformMakeTranslation(-100,100);
       CGAffineTransform transformB = CGAffineTransformScale(transformA, 0.5, 0.5);
        CGAffineTransform transformC = CGAffineTransformRotate(transformB, M_PI_4);
        self.tempView.transform = transformC;
    }];

            //清空transform的所有形变
            self.tempView.transform = CGAffineTransformIdentity ;

你可能感兴趣的:(IOS中UIView的transform(形变属性))