有了這么一個(gè)需求,肯定是所有的touch事件,但是通常我們知道的是touchBegan等觸摸事件,可是這些方法在點(diǎn)擊按鈕等方法時(shí)就沒有反應(yīng)了,查了很久后找到了一個(gè)方法
新建一個(gè)繼承與UIApplication的類
@interface **OC類名字** : UIApplication
@property (nonatomic,strong)NSTimer *Timer;
-(void)resetTimer;
@end
然后實(shí)現(xiàn)文件.m
-(void)sendEvent:(UIEvent *)event{
[super sendEvent:event];
if (!self.Timer) {
[self resetTimer];
}
NSSet *allTouches = [event allTouches];
if ([allTouches count]>0) {
UITouchPhase phase = ((UITouch *)[allTouches anyObject]).phase;
if (phase == UITouchPhaseBegan) {
[self resetTimer];
}
}
}
-(void)resetTime{
if (self.shutDownTimer) {
[self.Timer invalidate];
}
self.Timer = [NSTimer scheduledTimerWithTimeInterval:**設(shè)定不操作后時(shí)間** target:self selector:@selector(notifyToAction) userInfo:nil repeats:NO];
}
-(void)notifyToAction{
[[NSNotificationCenter defaultCenter]postNotificationName:@"ActionD" object:nil];
}
然后在需要的地方接受ActionD的通知去執(zhí)行操作。最后還要做的就是,去main.m
引入你所新建類的頭文件
@autoreleasepool {
return UIApplicationMain(argc, argv, NSStringFromClass([**新建類** class]), NSStringFromClass([AppDelegate class]));
}
簡(jiǎn)單記錄下