【发布时间】:2012-11-03 06:34:46
【问题描述】:
我的应用有一些问题。因此,当手指移出触摸对象(按钮)时,我需要停止 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];
}
感谢您的帮助!
【问题讨论】:
-
错误或问题是什么?
-
错误是什么?另外,添加时间 = nil; [时间失效]之后;
-
好的,当我将手指移动到另一个对象时,计时器不会停止
-
确保您没有多次发送计时器。
-
时间类型是强对象吗?
标签: iphone ios xcode ipad ios6