アプリに問題があります。そのため、触れたオブジェクト(ボタン)から指が離れたときに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];
}
助けてくれてありがとう!