美文网首页
02.5-CALayer和CATransform3D

02.5-CALayer和CATransform3D

作者: weyan | 来源:发表于2018-11-26 08:31 被阅读0次

一、CALayer

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置边框
    self.imageView.layer.borderColor = [UIColor blueColor].CGColor;
    self.imageView.layer.borderWidth = 3;
    
    //设置阴影
    //阴影的不透明度0-1,
    self.imageView.layer.shadowOpacity = 1;
    self.imageView.layer.shadowOffset = CGSizeMake(-10, 10);
    self.imageView.layer.shadowColor = [UIColor greenColor].CGColor;
    
    //设置圆角
//    self.imageView.layer.cornerRadius = 50;
    //超过根层以外的内容给裁剪掉
    //self.imageView.clipsToBounds = YES;
//    self.imageView.layer.masksToBounds = YES;
    
    NSLog(@"%@",self.imageView.layer.contents);
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    //设置边框
    self.redView.layer.borderColor = [UIColor blueColor].CGColor;
    self.redView.layer.borderWidth = 3;
    
    //设置阴影
    //阴影的不透明度0-1,
    self.redView.layer.shadowOpacity = 1;
    self.redView.layer.shadowOffset = CGSizeMake(-10, 10);
    self.redView.layer.shadowColor = [UIColor greenColor].CGColor;
    
    //设置圆角
    self.redView.layer.cornerRadius = 50;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

二、CATransform3D

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    [UIView animateWithDuration:0.5 animations:^{
        
        //旋转
        //self.imageView.layer.transform = CATransform3DMakeRotation(M_PI, 1, 1, 0);
        //平移
        //self.imageView.layer.transform =  CATransform3DTranslate(self.imageView.layer.transform, 50, 50, 0);
        //缩放
        //self.imageView.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1);
        
        //把结构体转成对象
        //KVC使用场景,用来做快速形变操作,只做一个值的操作
        //NSValue *valeu = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 1, 1, 0)];
        //[self.imageView.layer setValue:valeu forKeyPath:@"transform"];
        
        [self.imageView.layer setValue:@(100) forKeyPath:@"transform.translation.x"];
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

三、UIView和CALayer的选择



四、CALayer的隐式动画


相关文章

网友评论

      本文标题:02.5-CALayer和CATransform3D

      本文链接:https://www.haomeiwen.com/subject/ftqfxqtx.html