gpt4 book ai didi

ios - 如何在ios中制作圆形动画

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:03:42 25 4
gpt4 key购买 nike

如果我单击锻炼按钮,我想显示红色圆形动画和圆形图像。我想在 Storyboard 中移动另一个类。我怎样才能做到这一点?

enter image description here

enter image description here

最佳答案

使用UIBezierPathCAShapeLayer,您可以实现这一点。我在我的一个项目中测试了以下代码并发现它有效:

- (void)viewDidLoad
{
[super viewDidLoad];

int radius = 50;
CAShapeLayer *circle = [CAShapeLayer layer];
// Make a circular shape
circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius)
cornerRadius:radius].CGPath;
// Center the shape in self.view
circle.position = CGPointMake(CGRectGetMidX(self.view.frame)-radius,
CGRectGetMidY(self.view.frame)-radius);

// Configure the apperence of the circle
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = [UIColor redColor].CGColor;
circle.lineWidth = 5;

// Add to parent layer
[self.view.layer addSublayer:circle];

// Configure animation
CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
drawAnimation.duration = 5.0;
drawAnimation.repeatCount = 1.0; // Animate only once..

// Animate from no part of the stroke being drawn to the entire stroke being drawn
drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
drawAnimation.toValue = [NSNumber numberWithFloat:1.0f];

// Experiment with timing to get the appearence to look the way you want
drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

// Add the animation to the circle
[circle addAnimation:drawAnimation forKey:@"draw"];
// Do any additional setup after loading the view, typically from a nib.
}

输出如下:

enter image description here

关于ios - 如何在ios中制作圆形动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26136422/

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