tags:

views:

23

answers:

1

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!

A: 

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;
}
vodkhang