0

我正在使用 - (void)touchesBegan... 来判断用户是否点击了屏幕上的任何位置。一旦用户点击屏幕,就会执行一个动作。然而,只要那个人抬起手指,动作就会停止。具体来说,当用户点击时,我正在运行一次 imageView.animateImages。我想这样做,如果他们点击并放手,动画将继续运行(我将 repeatCount 设置为 1)。有谁知道如何做到这一点?提前致谢!

4

1 回答 1

0

You should probably use NSNotifications. Try something like this:

...

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; 
[nc addObserver:self selector:@selector(nameOfAnimationMethod) name:@"touched" object:nil];

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [nc postNotificationName:@"touched" object:self]; 
} 

Let me run you through what this does. It creates a notification center, and adds the current object as an observer to the notification center, listening for the notification "touched". When the notification center posts the said notification, the object runs the method (selector) "nameOfAnimationMethod". If you look at the touchesBegan method override, you'll see that I posted a notification by the name "touched". This will trigger the object to run the method that you wanted it to.

于 2012-05-12T23:59:21.090 回答