Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 不停止UIView动画的图像的当前位置_Ios_Iphone_Objective C_Uiviewanimation - Fatal编程技术网

Ios 不停止UIView动画的图像的当前位置

Ios 不停止UIView动画的图像的当前位置,ios,iphone,objective-c,uiviewanimation,Ios,Iphone,Objective C,Uiviewanimation,我想将图像移动到某个位置。我还需要每秒检查一次图像的当前位置,看它是否到达了那个特定的位置。因此,我做了以下工作: -(void)viewWillAppear:(BOOL)animated{ [self moshaMoveUp:mosha1 with:206 and:89]; playerLifeCount = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(deductPlayerLi

我想将图像移动到某个位置。我还需要每秒检查一次图像的当前位置,看它是否到达了那个特定的位置。因此,我做了以下工作:

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

}

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

实现这一点的理想方法是使用计时器绑定的方法调用(例如
update
)移动图像,而不是UIView动画

为图像的每个计时器调用插值x、y坐标,然后使用相同的方法(插值后)检查图像的帧及其位置以调用
deductPlayerLife


当你在游戏中工作时,我建议你也去寻找游戏开发的基础知识,这肯定会给你带来
更新
的建议。

实现这一点的理想方法是使用限时方法调用(例如
更新
)来移动你的图像,而不是UIView动画

为图像的每个计时器调用插值x、y坐标,然后使用相同的方法(插值后)检查图像的帧及其位置以调用
deductPlayerLife


当你正在制作一个游戏时,我建议你也去寻找游戏开发的基础知识,这肯定会建议你更新这个东西。

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

您将得到mosha的如下立场:

CGRect moshaFrame = [[mosha1.layer presentationLayer] frame];
如果尚未导入Quartzcore,请不要忘记导入

#import <QuartzCore/QuartzCore.h>
#导入

另外,我会用动画块来代替。由于iOS 4.0,不鼓励使用动画样式。

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

您将得到mosha的如下立场:

CGRect moshaFrame = [[mosha1.layer presentationLayer] frame];
如果尚未导入Quartzcore,请不要忘记导入

#import <QuartzCore/QuartzCore.h>
#导入
另外,我会用动画块来代替。由于iOS 4.0,不鼓励使用动画样式