设置UIview的动画属性
//边框宽度
self.ouroleView.layer.borderWidth=10;
//边框颜色
self.ouroleView.layer.borderColor=[UIColor blueColor].CGColor;
//圆角
self.ouroleView.layer.cornerRadius=10;
//阴影
self.ouroleView.layer.shadowColor=[UIColor blackColor].CGColor;
//阴影偏差
self.ouroleView.layer.shadowOffset=CGSizeMake(10, 10);
//阴影不透明度
self.ouroleView.layer.shadowOpacity=0.5;
//为YES的话 超出边框的部分就给剪掉
self.ouroleView.layer.masksToBounds=NO;
设置UIImageView的动画属性
// //边框宽度
// self.imgView.layer.borderWidth=10;
//
// //边框颜色
// self.imgView.layer.borderColor=[UIColor greenColor].CGColor;
//圆角
self.imgView.layer.cornerRadius=10;
//阴影
self.imgView.layer.shadowColor=[UIColor blackColor].CGColor;
//阴影偏差
self.imgView.layer.shadowOffset=CGSizeMake(10, 10);
//阴影不透明度
self.imgView.layer.shadowOpacity=0.5;
//为YES的话 超出边框的部分就给剪掉 阴影就会没有
self.imgView.layer.masksToBounds=YES;
//缩放
// self.imgView.layer.transform=CATransform3DMakeScale(1.5, 0.5, 1);
//旋转 x y z 确定绕着什么转
// self.imgView.layer.transform=CATransform3DMakeRotation(M_PI_4, 0, 0, 1);
//创建图层
//新建图层
CALayer * layer =[CALayer layer];
layer.backgroundColor=[UIColor redColor].CGColor;
layer.bounds=CGRectMake(0, 0, 100, 100);
layer.position=CGPointMake(100, 300);
layer.cornerRadius=10;
layer.contents=(__bridge id)([UIImage imageNamed:@"a2.jpg"].CGImage);
layer.masksToBounds=YES;
//添加到控制器
[self.view.layer addSublayer:layer];
隐式动画
当对非Root Layer的部分属性进行修改时,默认是自动产生一些动画效果
self.layer =[CALayer layer];
_layer.bounds=CGRectMake(0, 0, 100, 100);
_layer.backgroundColor=[UIColor yellowColor].CGColor;
_layer.position=CGPointZero;
//锚点 决定着CALayer身上的那个点会在position属性所指的位置
_layer.anchorPoint=CGPointZero;
[self.view.layer addSublayer:_layer];
在开始点击触碰里面设置事件
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"------开始触碰");
// self.layer.backgroundColor=[UIColor blueColor].CGColor;
self.layer.opacity=0.5;
}