美文网首页移动端(android || ios)
iOS单击和双击冲突事件

iOS单击和双击冲突事件

作者: 螢火蟲的瘋狂 | 来源:发表于2018-03-13 18:00 被阅读0次

    // 单击的 Recognizer    

        UITapGestureRecognizer* singleRecognizer;    

    singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SingleTap:)];    

    //点击的次数    

    singleTapRecognizer.numberOfTapsRequired = 1; // 单击    

    //给self.view添加一个手势监测;   

    [self.view addGestureRecognizer:singleRecognizer];   

    // 双击的 Recognizer    

    UITapGestureRecognizer* doubleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(DoubleTap:)];    

    doubleRecognizer.numberOfTapsRequired = 2; // 双击    

    //关键语句,给self.view添加一个手势监测;    

    [self.view addGestureRecognizer:doubleRecognizer];    

    // 关键在这一行,双击手势确定监测失败才会触发单击手势的相应操作    

    [singleRecognizer requireGestureRecognizerToFail:doubleRecognizer];   

    -(void)SingleTap:(UITapGestureRecognizer*)recognizer    

    {    

    //处理单击操作    

    }    

    -(void)DoubleTap:(UITapGestureRecognizer*)recognizer    

    {    

    //处理双击操作    

    相关文章

      网友评论

        本文标题:iOS单击和双击冲突事件

        本文链接:https://www.haomeiwen.com/subject/zettqftx.html