Reputation: 5009
How can i repeatedly run this method as long as the button is being held down. This way the image is moved up as long as the button is being held down.
-(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];
}
Thanks!
Upvotes: 0
Views: 140
Reputation: 18741
You can register for 2 control events:
[yourButton addTarget:self action:@selector(doneButtonPressed) forControlEvents:UIControlEventTouchDown];
[yourButton addTarget:self action:@selector(doneButtonReleased) forControlEvents:UIControlEventTouchUpInside];
and then handle 2 methods:
- (void)doneButtonPressed {
// open a thread
while(someBOOL) {
//do something you want
}
}
- (void)doneButtonReleased {
// do something
someBOOL = NO;
}
Upvotes: 1