iOS图层layer操做

#####图层layer #####1.操做view图层(代码加注释) #####1.1属性操做git

#pragma mark - layerView
-(void)layView{
    //背景颜色
    self.lView.layer.backgroundColor=[UIColor yellowColor].CGColor;
    //线宽度
    self.lView.layer.borderWidth=1;
    //图层的颜色都是核心绘图框架,cg开头
    //线条颜色
    self.lView.layer.borderColor=[UIColor redColor].CGColor;
    //阴影不透明度
    self.lView.layer.shadowOpacity=1;
    //阴影偏移量
    self.lView.layer.shadowOffset=CGSizeMake(5, 5);
    //圆角
    self.lView.layer.cornerRadius=20;
}

#####1.2变换操做github

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //图层的3D变换
    //缩放
    [UIView animateWithDuration:1 animations:^{
        self.lView.layer.transform=CATransform3DScale(self.lView.layer.transform, 0.5, 0.5, 0.5);

        self.lView.layer.transform=CATransform3DMakeRotation(M_PI, 1, 1, 0);
    }];

    //
}

#####2. UIImageView的图层操做 #####2.1 UIImageView的图层操做框架

-(void) imageLayer{
    CALayer *layer=[CALayer layer];
    layer.frame=CGRectMake(0, 0, 200, 200);
    layer.backgroundColor=[UIColor redColor].CGColor;
    //    layer.contents=[UIImage imageNamed:@"阿狸头像"];
    layer.contents=(id)[UIImage imageNamed:@"阿狸头像"].CGImage;
    [self.imageView.layer addSublayer:layer];
}

#####2.2 UIImageView的图层裁剪操做dom

图片
-(void) imageLayer2{
    CALayer *layer=[CALayer layer];
    layer.frame=CGRectMake(0, 0, 200, 200);
    layer.backgroundColor=[UIColor redColor].CGColor;
    layer.cornerRadius=100;
    //    layer.contents=[UIImage imageNamed:@"阿狸头像"];
    layer.contents=(id)[UIImage imageNamed:@"阿狸头像"].CGImage;
    //超出主层边框的内容所有裁剪掉
    layer.masksToBounds=YES;
    //添加边框
    layer.borderColor=[UIColor greenColor].CGColor;
    layer.borderWidth=2;
    [self.imageView.layer addSublayer:layer];
}

#####3.隐式动画动画

  • 全部非root layer,也就是手动建立的calayer对象,才会有隐式动画。
- (void)viewDidLoad {
    [super viewDidLoad];
    self.layer=[CALayer layer];
    self.layer.frame=CGRectMake(150, 350, 80,80);
    self.layer.backgroundColor=[UIColor blueColor].CGColor;
    [self.view.layer addSublayer:self.layer];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //
    CGFloat angle=(arc4random_uniform(360)+1)/(M_PI*2);
    self.layer.transform=CATransform3DMakeRotation(angle, 0, 0, 1);
}

#####4.源代码详细地址.net

相关文章
相关标签/搜索