我正在研究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];
}
}