CAReplicatorLayer *repLayer = [CAReplicatorLayer layer];
repLayer.bounds = CGRectMake(0, 0, 100, 100);
repLayer.position = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
repLayer.backgroundColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:0.2].CGColor;
repLayer.cornerRadius = 10;
[self.view.layer addSublayer:repLayer];
CALayer *dotLayer = [CALayer layer];
dotLayer.bounds = CGRectMake(0, 0, 15, 5);
dotLayer.position = CGPointMake(15, repLayer.frame.size.height/2);
dotLayer.backgroundColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:0.6].CGColor;
dotLayer.cornerRadius = 2.5;
[repLayer addSublayer:dotLayer];
int count = 12;
repLayer.instanceCount = count;
CGFloat angel = 2*M_PI / count;
repLayer.instanceTransform = CATransform3DMakeRotation(angel, 0, 0, 1);
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
anim.duration = 1.0;
anim.fromValue = @0.6;
anim.toValue = @0;
anim.repeatCount = MAXFLOAT;
repLayer.instanceDelay = 1.0/count;
[dotLayer addAnimation:anim forKey:nil];
Loading图代码
最新推荐文章于 2020-12-25 12:43:46 发布
本文介绍如何利用Core Animation中的CAReplicatorLayer创建动态用户界面元素。通过实例演示了设置复制层的基本属性,如位置、大小、背景颜色及圆角,并展示了如何添加子图层以及设置旋转动画和透明度变化动画。
144

被折叠的 条评论
为什么被折叠?



