gpt4 book ai didi

iphone - CoreAnimation CALayer 和 CATextLayer 组合

转载 作者:行者123 更新时间:2023-12-03 18:57:31 25 4
gpt4 key购买 nike

我最近在玩CA。现在我有点卡住了。这就是我想要制作动画的东西: enter image description here

现在我已经让圆形动画正常工作了。我将 CALayer 子类化来制作动画。我真的不知道从这里该去哪里。我必须在哪里添加 CATextLayer 的子图层?如何同时对两者进行动画处理,以便文本及其线条看起来粘在圆的末端?

如果您需要一些代码或其他任何东西,请告诉我。

我真的很高兴在这里得到一些帮助:-)

非常感谢!

最佳答案

我能够完成您在下面提出的要求。代码非常粗糙,只花了几分钟,可能错过了发布以及您有什么。您只需将 UILabel 替换为 CATextLayer(为简洁起见,使用 UILabel)。

    CAShapeLayer* circle = [[CAShapeLayer alloc] init];
CGMutablePathRef path = CGPathCreateMutable();
CGRect textRect = CGRectMake(self.bounds.size.width/4, (self.bounds.size.height-self.bounds.size.width/2)/2, self.bounds.size.width/2, self.bounds.size.width/2);
float midX = CGRectGetMidX(textRect);
float midY = CGRectGetMidY(textRect);
CGAffineTransform t = CGAffineTransformConcat(
CGAffineTransformConcat(
CGAffineTransformMakeTranslation(-midX, -midY),
CGAffineTransformMakeRotation(-1.57079633/0.99)),
CGAffineTransformMakeTranslation(midX, midY));
CGPathAddEllipseInRect(path, &t, textRect);
circle.path = path;
circle.frame = self.bounds;
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = [UIColor blackColor].CGColor;
circle.lineWidth = 60.0f;
[self.layer addSublayer:circle];

CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.duration = 15.0f;
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat:1.0f];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[circle addAnimation:animation forKey:@"strokeEnd"];

[circle release];

UILabel* label = [[UILabel alloc] init];
label.text = @"Test Text";
label.font = [UIFont systemFontOfSize:20.0f];
label.center = CGPathGetCurrentPoint(path);
label.transform = CGAffineTransformMakeRotation(1.57079633);
[label sizeToFit];
[self.layer addSublayer:label.layer];

CAKeyframeAnimation* textAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
textAnimation.duration = 15.0f;
textAnimation.path = path;
textAnimation.rotationMode = kCAAnimationRotateAuto;
textAnimation.calculationMode = kCAAnimationCubicPaced;
textAnimation.removedOnCompletion = NO;
[label.layer addAnimation:textAnimation forKey:@"position"];

关于iphone - CoreAnimation CALayer 和 CATextLayer 组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7947529/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com