iOS开发基础 - CALayer的使用

//CALayer 层(图层)
//每个view(视图)都附着在一个层上 通过改变这个层 可以改变view的形状、边框、颜色等等

UIView *redView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

//设置锚点 即中心点
cell.layer.anchorPoint = CGPointMake(0, 0);
redView.backgroundColor = [UIColor redColor];
//CALayer view的属性 修改view的圆角
redView.layer.cornerRadius = 20;
//设置边框宽度
redView.layer.borderWidth = 8.f;
//设置边框颜色 颜色的CGColor
redView.layer.borderColor = [UIColor greenColor].CGColor;
//剪切超出的部分
redView.layer.masksToBounds = YES;

//设置圆头像

UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(100, 220, 100, 100)];
imageV.image = [UIImage imageNamed:@"image1"];
self.view.backgroundColor = [UIColor blueColor];

imageV.layer.cornerRadius = 50; 
imageV.layer.masksToBounds = YES;

[self.view addSubview:redView];
[self.view addSubview:imageV];

//动画

//CAAnimation动画类  创建按一个动画
CAAnimation *anima = [CAAnimation animation];
//CAAnimation 的子类 CATransition
CATransition *tans = [CATransition animation];
//选择动画的类型
tans.type = @"fade";
//动画的方向
tans.subtype = @"fromRight";
//动画的时间
tans.duration = 2.0;
//动画的次数
tans.repeatCount = 2;
//在layer层上添加动画
//[redView.layer addAnimation:tans forKey:@"key1"];
//移除layer层的动画
//[redView.layer removeAnimationForKey:@"key1"];

//三维动画
CABasicAnimation *baAnima = [CABasicAnimation animationWithKeyPath:@"transform"];
//第一个参数:角度   x x轴 y y轴 z z轴
NSValue *value = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(3.14, 2, 1, 0)];
baAnima.toValue = value;
baAnima.duration = 2.0;
baAnima.repeatCount = 60;
//在layer层上添加动画
[imageV.layer addAnimation:baAnima forKey:@"key2"];

你可能感兴趣的:(iOS开发基础 - CALayer的使用)