user3534757
user3534757

Reputation: 161

Change position of animation?

I'm using this code I have modified from a previous stackOverFlow post.I want to change position of the animation, but when i run it will not change to where i want it to be. Instead it will be some pixels away. Basically what I want is that I want to input an X value or Y between 480-0 and 320-0 and get the animation to that position using circle.position. How can I do this?

-(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;
}

Upvotes: 0

Views: 175

Answers (1)

rdelmar
rdelmar

Reputation: 104082

Replace,

circle.position = CGPointMake(CGRectGetMidX(self.view.frame)-radius,
                                  CGRectGetMidY(self.view.frame)-radius);

with,

circle.position = CGPointMake(x-radius, y-radius);

Upvotes: 1

Related Questions