您的位置:首页 > 产品设计 > UI/UE

UIView 实现单击和双击的区别

2017-01-20 15:20 543 查看
1、viewload中添加UITapGestureRecognizer识别    

// double tap

    UITapGestureRecognizer * doubleTapRecognizer=

    [[UITapGestureRecognizer
alloc]initWithTarget:self
action:@selector(doubleTap:)];

    doubleTapRecognizer.numberOfTapsRequired=2;

    doubleTapRecognizer.delaysTouchesBegan=YES;

    [self.view
addGestureRecognizer:doubleTapRecognizer];

    

    // single tap

    UITapGestureRecognizer *tapRecognizer=

    [[UITapGestureRecognizer
alloc]initWithTarget:self
action:@selector(tap:)];

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

    [tapRecognizer requireGestureRecognizerToFail:doubleTapRecognizer];

    [self.view
addGestureRecognizer:tapRecognizer];

2、实现相关触发事件

-(void)doubleTap:(UIGestureRecognizer *) gr

{

    NSLog(@"doubleTap");

}

-(void)tap:(UIGestureRecognizer *) gr

{

    NSLog(@"tap");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: