gpt4 book ai didi

ios - 在不停止 UIView 动画的情况下图像的当前位置

转载 作者:行者123 更新时间:2023-11-28 18:34:31 24 4
gpt4 key购买 nike

我想将图像移动到某个位置。而且我还需要每秒检查图像的当前位置是否到达该特定位置。所以,我做了以下事情:

-(void)viewWillAppear:(BOOL)animated{

[self moshaMoveUp:mosha1 with:206 and:89];
playerLifeCount = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(deductPlayerLife) userInfo:nil repeats:YES];

}

-(void)moshaMoveUp: (UIImageView *)mosha with:(int)x and:(int)y{

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:7.0];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
mosha.center = CGPointMake(x, y);
[UIView commitAnimations];

}

但问题是当最开始调用'moshaMoveUp'方法时,图像的中心设置为(206,89)。因此,每一秒我都会检查当前位置,它会显示我希望图像到达的位置的结果,而不是当前位置。即使图像尚未到达该位置。

-(void)deductPlayerLife{

NSLog(@"x : %f",mosha1.frame.origin.x);
NSLog(@"y : %f",mosha1.frame.origin.y);

}

那么,如何在不停止图像运动的情况下每秒获取该图像的真实当前位置。

最佳答案

要获取动画的当前位置,可以使用 QuartzCore presentationLayer

您将获得 mosha 的位置,如下所示:

CGRect moshaFrame = [[mosha1.layer presentationLayer] frame];

如果您还没有导入 Quartzcore,请不要忘记导入它。

#import <QuartzCore/QuartzCore.h>

附言我会改用动画 block 。自 iOS 4.0 以来,不鼓励使用您的动画样式。

关于ios - 在不停止 UIView 动画的情况下图像的当前位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21725928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com