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"];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值