美文网首页
#浅析CALayer

#浅析CALayer

作者: Z了个L | 来源:发表于2016-12-21 19:39 被阅读18次
    
    // ViewController.h
    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController
    
    
    @end
    
    // ViewController.m
    
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @property (weak, nonatomic) IBOutlet UIView *redView;
    @property (weak, nonatomic) IBOutlet UIImageView *imageV;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        [self UIViewLayer];
    }
    
    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
        
        //只有在旋转的时候才能看3D
        [UIView animateWithDuration:0.5 animations:^{
            
            // 旋转
    //        self.imageV.layer.transform = CATransform3DMakeRotation(M_PI, 0.5, 0, 0);
    //        self.imageV.layer.transform = CATransform3DMakeScale(0.5, 0.5, 0);
    //        self.imageV.layer.transform = CATransform3DTranslate(self.imageV.layer.transform, 100, 0, 0);
            self.imageV.layer.transform = CATransform3DRotate(self.imageV.layer.transform, M_PI, 0.5, 0, 0);
            // 把结构体转成对象
            // 通过KVC做一些快速平移旋转,缩放
    //         NSValue *value = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 1, 1, 0)];
    //        [self.imageV.layer setValue:@(M_PI) forKeyPath:@"transform.scale.x"];
        }];
    }
    
    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
        //设置边框(边框宽度往里走的)
        self.imageV.layer.borderColor = [UIColor greenColor].CGColor;
        self.imageV.layer.borderWidth = 3;
    
        //设置阴影
        self.imageV.layer.shadowColor = [UIColor blueColor].CGColor;
        self.imageV.layer.shadowOpacity = 1;
        self.imageV.layer.shadowOffset = CGSizeMake(-10, 10);
        self.imageV.layer.shadowRadius = 10;
    
        //设置圆角
        self.imageV.layer.cornerRadius = 50;
        //超过根层以久的内容就会自动裁剪掉
        self.imageV.layer.masksToBounds = YES;
    
    //    NSLog(@"%@",self.imageV.layer.sublayers);
    //    NSLog(@"%@",self.imageV.layer.contents);
    }
    
    
    - (void)UIViewLayer {
    
        //设置边框(边框宽度往里走的)
        self.redView.layer.borderColor = [UIColor greenColor].CGColor;
        self.redView.layer.borderWidth = 3;
        //设置阴影
        self.redView.layer.shadowColor = [UIColor blueColor].CGColor;
        self.redView.layer.shadowOpacity = 1;
        self.redView.layer.shadowOffset = CGSizeMake(-10, 10);
        self.redView.layer.shadowRadius = 10;
    
        //设置圆角
        self.redView.layer.cornerRadius = 50;
    }
    
    
    @end
    
    
    
    • 效果图:

    相关文章

      网友评论

          本文标题:#浅析CALayer

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