图层的transform属性

时间:2021-01-04 20:58:27

Main.storyboard

图层的transform属性

//

//  ViewController.m

//  7A11.图层的transform属性

//

//  Created by huan on 16/2/4.

//  Copyright © 2016年 huanxi. All rights reserved.

//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@property (weak, nonatomic) IBOutlet UIView *redView;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

self.redView.layer.contents = (id)[UIImage imageNamed:@"papa"].CGImage;

}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

//学习形变的属性

//缩放

//第三个参数sz 看不到效果

//    self.redView.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5);

//旋转

//1,0,0 x轴旋转

//0,1,0 y轴旋转

//0,0,1 z轴旋转

//    self.redView.layer.transform = CATransform3DMakeRotation(M_PI_4, 0, 0, 1);

//平移

//    self.redView.layer.transform = CATransform3DMakeTranslation(10, 10, 0);

//使用kvc的方法 改变 属性值

//    [self.redView.layer setValue:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.5, 1.5, 1)] forKey:@"transform"];

#warning transform里面有更具体的形变属性

//缩放

//transform.scale.x 代表x方向上

//transform.scale.y 代表y方向上

//    [self.redView.layer setValue:@1.5 forKeyPath:@"transform.scale.x"];

//旋转

// transform.rotation.z z轴旋转

//    [self.redView.layer setValue:@(M_PI_4) forKeyPath:@"transform.rotation.z"];

//平移

//transform.translation.x x方向移动

//    [self.redView.layer setValue:@(20)forKeyPath:@"transform.translation.x"];

//不具体指定x还是y方向的移动

//    [self.redView.layer setValue:[NSValue valueWithCGPoint:CGPointMake(20, 20)] forKeyPath:@"transform.translation"];

#warning kvc设置不仅限于transform属性,只要layer有的属性,都设置

[self.redView.layer setValue:[NSValue valueWithCGRect:CGRectMake(0, 0, 200, 200)] forKeyPath:@"bounds"];

}

@end

结果

图层的transform属性