我的应用程序有一些问题。因此,当手指移出触摸对象(按钮)时,我需要停止 NStimer。所以有一个代码:
-(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];
}
谢谢你的帮助!