我正在研究iPhone应用程序,而在我的应用程序中有一个从屏幕顶部移动到底部的对象。为此,我使用CAD显示链接。一旦对象离开屏幕,它应该重新启动它的路线。我遇到的问题是每次对象重新启动它的路由时,它都会加速。这样继续下去,直到物体变得如此之快以至于几乎看不到它。任何想法,为什么发生这种情况,以及如何阻止它?任何帮助表示感谢,提前致谢!每次调用方法时,CAD显示链接似乎都在加快速度
-(void)spawnButton{
int x = (arc4random() % (240) + 40;
int y = -100;
button1.center = CGPointMake(x,y);
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(moveObject)];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}
-(void) moveObject {
int z = 1;
button1.center = CGPointMake(button1.center.x , button1.center.y +z);
if (button1.center.y >= 480) {
[self spawnButton];
}
}