转载连接:ios监听用户是否触摸了屏幕的一种实现
1、修改 AppDelegate 继承 UIApplication ,而不是直接继承 UIResponder
2、为了能让继承了UIApplication的AppDelegate起作用,需要将main.m中的更改为:
return UIApplicationMain(argc, argv, NSStringFromClass([AppDelegate class]), NSStringFromClass([AppDelegate class]));
3、重新sendEvent:(UIEvent *)event
- (void)sendEvent:(UIEvent *)event
{
[super sendEvent:event];//这里一定不能漏掉,否则app将不能成功启动。
NSSet *allTouches = [event allTouches];
if ([allTouches count] > 0)
{
UITouchPhase phase = ((UITouch *)[allTouches anyObject]).phase;
if (phase == UITouchPhaseBegan){
NSLog(@"send UITouchPhaseBegan");
}
if (phase == UITouchPhaseEnded){
NSLog(@"send UITouchPhaseEnded");
}
if (phase == UITouchPhaseMoved) {
}
if (phase == UITouchPhaseCancelled) {
}
}
}
本文介绍了iOS监听用户是否触摸屏幕的一种实现方法。包括修改AppDelegate继承UIApplication,更改main.m中的代码,以及重新实现sendEvent方法,在该方法中根据触摸阶段输出相应日志,同时强调不能漏掉调用父类方法,否则app无法启动。
4475

被折叠的 条评论
为什么被折叠?



