您的位置:首页 > 移动开发 > IOS开发

iOS图层layer操作

2016-07-04 00:00 513 查看
摘要: iOS图层layer操作

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

#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变换操作

-(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的图层裁剪操作




-(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.源代码详细地址

github基本代码

隐式动画
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS图层layer操作