2010-08-02 89 views
0

只要按住按钮,我如何重复运行此方法。这样,只要按住按钮,图像就会向上移动。Cocoa Touch - 按住按钮

-(IBAction)thrustButton{ //moves ship foward 

    yCoordinate = yCoordinate - 2; 

    [UIView beginAnimations:@"slide-up" context:NULL]; 
    shipImageView.center = CGPointMake(xCoordinate,yCoordinate); // change this to somewhere else you want. 
    [UIView commitAnimations]; 
} 

谢谢!

回答

1

可以为2组控制寄存器的事件:

[yourButton addTarget:self action:@selector(doneButtonPressed) forControlEvents:UIControlEventTouchDown]; 


[yourButton addTarget:self action:@selector(doneButtonReleased) forControlEvents:UIControlEventTouchUpInside]; 

,然后处理2种方法:

- (void)doneButtonPressed { 
    // open a thread 
    while(someBOOL) { 
    //do something you want 
    } 
} 

- (void)doneButtonReleased { 
    // do something 
    someBOOL = NO; 
}