020606-05-transform

//
//  ViewController.m
//  05-transform
#import "ViewController.h"

@interface ViewController ()
@property (nonatomic, strong) UIView *tempView;

//@property (nonatomic, assign) CGFloat angle;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    [tempView addSubview:[[UISwitch alloc] init]];
    tempView.backgroundColor = [UIColor redColor];
    tempView.transform = CGAffineTransformMakeRotation(M_PI_4);
    [self.view addSubview:tempView];
    self.tempView = tempView;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    // 清空transform,以前的平移、缩放、旋转都会消失
    [UIView animateWithDuration:2.0 animations:^{
        self.tempView.transform = CGAffineTransformIdentity;
        
    }];
    
//    self.angle += M_PI_4;
    
//    [UIView animateWithDuration:1.0 animations:^{
////        self.tempView.transform = CGAffineTransformScale(self.tempView.transform, 0.8, 0.8);
//        self.tempView.transform = CGAffineTransformRotate(self.tempView.transform, M_PI_4);
//    }];
    
    
    // transform:形变属性,能完成的功能:平移、缩放、旋转
//    [UIView animateWithDuration:2.0 animations:^{
//        // 缩放
//        self.tempView.transform = CGAffineTransformMakeScale(0.5, 0.5);
//        // 平移
//        self.tempView.transform = CGAffineTransformMakeTranslation(-100, 100);
        // 旋转
//        self.tempView.transform = CGAffineTransformMakeRotation(-M_PI_4);
        
//        CGAffineTransform translation = CGAffineTransformMakeTranslation(-100, 100);
//        CGAffineTransform scaleTranslation = CGAffineTransformScale(translation, 0.5, 0.5);
//        CGAffineTransform rotateScaleTranslation = CGAffineTransformRotate(scaleTranslation, M_PI_2);
//        self.tempView.transform = rotateScaleTranslation;
//    }];
}

@end
本人无商业用途,仅仅是学习做个笔记,特别鸣谢小马哥,学习了IOS,另日语学习内容有需要文本和音频请关注公众号:riyuxuexishuji
原文地址:https://www.cnblogs.com/laugh/p/6508903.html