Ios 改变动画的位置?
我使用的代码是我在上一篇stackOverFlow文章中修改的。我想更改动画的位置,但当我运行它时,它不会更改到我想要的位置。相反,它将是一些像素远。基本上我想要的是,我想要输入一个480-0和320-0之间的X值或Y值,并使用circle.position将动画设置到该位置。我该怎么做Ios 改变动画的位置?,ios,objective-c,Ios,Objective C,我使用的代码是我在上一篇stackOverFlow文章中修改的。我想更改动画的位置,但当我运行它时,它不会更改到我想要的位置。相反,它将是一些像素远。基本上我想要的是,我想要输入一个480-0和320-0之间的X值或Y值,并使用circle.position将动画设置到该位置。我该怎么做 -(CAShapeLayer *)addCircleYellownWithRadius:(float)radius5 withduration:(float)duration X:(float)x Y:(flo
-(CAShapeLayer *)addCircleYellownWithRadius:(float)radius5 withduration:(float)duration X:(float)x Y:(float)y{
int radius = (int)radius5;
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 whiteColor].CGColor;
circle.lineWidth = 5;
// Add to parent layer
[self.view.layer addSublayer:circle];
// Configure animation
CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
drawAnimation.duration = duration; // "animate over 10 seconds or so.."
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:@"drawCircleAnimation"];
return circle;
}
取代
circle.position = CGPointMake(CGRectGetMidX(self.view.frame)-radius,
CGRectGetMidY(self.view.frame)-radius);
有,
我很高兴看到“动画超过10秒左右…”的评论继续存在;)@戴维德龙·恩克维斯特几乎是,但(我认为)不完全是
circle.position = CGPointMake(x-radius, y-radius);