iOS 监听触屏,监听点击

转载连接: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) {

        }

    }

}

原创文章 98 获赞 14 访问量 15万+

猜你喜欢

转载自blog.csdn.net/TaLinBoy/article/details/90711895
今日推荐