I have some problems with my app. So, I need to stop NStimer when finger moved out of touched object (button). So there is a code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
for (UITouch *touch in allTouches)
{
CGPoint location = [touch locationInView:touch.view];
if ([testButton.layer.presentationLayer hitTest:location]) {
timer = 60;
time = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(randomVoid) userInfo:nil repeats:YES];
} else if (![testButton.layer.presentationLayer hitTest:location]){
[time invalidate];
}
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[time invalidate];
}
Thanks for any help!
touchesBeganevent executes when you press your finger on the screen. If you move your finger,touchesMovedis called for every move, and when you lift your finger,touchEndis called.So, basically you should add code for testing if desired button is touched to the
touchMovedmethod.