Pergunta

I have looked at every instance of this question on Stack as well as various other websites, its still not working out for me. I am trying to get the position of my object while the animation is in session.

Here is what I have:

- (void)viewDidLoad{
    currentPosition = [[bikeMotion.layer presentationLayer] center]; //its a CGPoint
}

- (void)doAnimation {
    bikeMotion = [[DotAnimation alloc]initWithFrame:CGRectMake((*bikePathPoints)[0].x, (*bikePathPoints)[0].y, 8, 8)];

    //... [self animate stuff]...
    [NSTimer scheduledTimerWithTimeInterval:0.07f target:self selector:@selector(backgroundAnimations) userInfo:nil repeats:YES];
}

-(void)backgroundAnimations{
    cout << currentPosition.x << endl;

}

I also tried this:

- (void)viewDidLoad{
    currentPosition = [[bikeMotion.layer presentationLayer] frame]; //its a CGRect
}

- (void)doAnimation {
    bikeMotion = [[DotAnimation alloc]initWithFrame:CGRectMake((*bikePathPoints)[0].x, (*bikePathPoints)[0].y, 8, 8)];
    //...[self animation stuff];
    [NSTimer scheduledTimerWithTimeInterval:0.07f target:self selector:@selector(backgroundAnimations) userInfo:nil repeats:YES];
}

-(void)backgroundAnimations{
    cout << currentPosition.origin.x << endl;

}

I have even tried this:

- (void)viewDidLoad{
    p = (CALayer*)[bikeMotion.layer presentationLayer];

}

-(void)doAnimation{
    bikeMotion = [[DotAnimation alloc]initWithFrame:CGRectMake((*bikePathPoints)[0].x, (*bikePathPoints)[0].y, 8, 8)];
    [NSTimer scheduledTimerWithTimeInterval:0.07f target:self selector:@selector(backgroundAnimations) userInfo:nil repeats:YES];
}

-(void)backgroundAnimations{
    CGPoint position = [p position];
    cout << position.x << endl;
}
Foi útil?

Solução

Have you tried object.layer.anchorpoint? You'll need to import QuartzCore.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top