2010-08-02 86 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; 
}