ios - 它在动画期间显示椭圆形而不是圆形(iOS)

标签 ios animation cabasicanimation

我想用CABasicAnimation画一个圆,但奇怪的是它在动画过程中显示了一个椭圆 代码如下:

 //---------------draw circle
// Set up the shape of the circle
int radius = 10;
CAShapeLayer *circle = [CAShapeLayer layer];
// Make a circular shape
circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2 ,self.view.frame.size.height/2) radius:radius startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath;
// Configure the apperence of the circle
circle.fillColor = [UIColor redColor].CGColor;
circle.strokeColor = [UIColor redColor].CGColor;
circle.lineWidth = 1;
// Add to parent layer
[self.view.layer addSublayer:circle];
// Configure animation
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
[pathAnimation setFromValue:(id)[UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2 ,self.view.frame.size.height/2) radius:0 startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath];
[pathAnimation setToValue:(id)[UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2 ,self.view.frame.size.height/2) radius:radius*1.2 startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath];
[pathAnimation setDuration:15.0f];
[pathAnimation setRepeatCount:1.0f];
[pathAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2) radius:radius startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath;
[circle addAnimation:pathAnimation forKey:@"changePathAnimation"]; 

我该如何处理。

最佳答案

这样试试,

CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
[pathAnimation setFromValue:(id)[UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2 ,self.view.frame.size.height/2) radius:10 startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath];
[pathAnimation setToValue:(id)[UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2 ,self.view.frame.size.height/2) radius:radius*1.2 startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath];
[pathAnimation setDuration:15.0f];
[pathAnimation setRepeatCount:1.0f];
[pathAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2) radius:radius startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath;
[circle addAnimation:pathAnimation forKey:@"changePathAnimation"]; 

关于ios - 它在动画期间显示椭圆形而不是圆形(iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19419371/

相关文章:

Css3 动画在 Firefox 版本 44 中不起作用

ios - 暂停和恢复加载屏幕的 CABasicAnimation?

ios - UITableViewCell动态高度+隐藏元素在Swift中占用空间?

android - libgdx 中使用单独纹理的动画

python - 一种使用 Python、Gtk 和 Cairo 动画转换的方法?

ios - swift : CABasicAnimation Issue

ios - 如何使用 CABasicAnimations 和自动布局替换 CGAffineTransform 缩放和 alpha 动画?

ios - AMSlideMenu - 调用左侧菜单以编程方式打开

android - 如何在没有本地依赖的情况下构建用于共享测试的 react native 应用程序

ios - postObject 的 Restkit 返回值