UIView 在 Animatoin 期间获取位置

发布于 2024-12-27 18:35:40 字数 1667 浏览 1 评论 0原文

我已经在 Stack 以及其他各种网站上查看了这个问题的每个实例,但它仍然不适合我。我试图在动画会话期间获取对象的位置。

这是我所拥有的:

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

}

我也尝试过这个:

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

}

我什至尝试过这个:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只为一人 2025-01-03 18:35:40

您尝试过object.layer.anchorpoint吗?您需要导入 QuartzCore。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文