只要按住按钮,我怎样才能重复运行此方法。这样,只要按下按钮,图像就会向上移动。
-(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];
}
谢谢!
答案 0 :(得分: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;
}