• ios 开发日记17-单击手势和双击手势共存问题


     

    iOS 单击手势和双击手势共存问题

    分类: IOS

    - (void)viewDidLoad

    {

        [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 110, 200)];

        imageView.contentMode = UIViewContentModeScaleAspectFit;

        [imageView setImage:[UIImage imageNamed:@"xxx.bundle/1.jpg"]];

        imageView.userInteractionEnabled = YES;

        [self.view addSubview:imageView];

        

        UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizeralloc]initWithTarget:self action:@selector(singleTap:)];

        [singleTapGestureRecognizer setNumberOfTapsRequired:1];

        [imageView addGestureRecognizer:singleTapGestureRecognizer];

        

        UITapGestureRecognizer *doubleTapGestureRecognizer = [[UITapGestureRecognizeralloc]initWithTarget:self action:@selector(doubleTap:)];

        [doubleTapGestureRecognizer setNumberOfTapsRequired:2];

        [imageView addGestureRecognizer:doubleTapGestureRecognizer];

        

        //这行很关键,意思是只有当没有检测到doubleTapGestureRecognizer 或者 检测doubleTapGestureRecognizer失败,singleTapGestureRecognizer才有效

        [singleTapGestureRecognizer requireGestureRecognizerToFail:doubleTapGestureRecognizer];

    }

    - (void)singleTap:(UIGestureRecognizer*)gestureRecognizer

    {

        NSLog(@"-----singleTap-----");

        [self.view setBackgroundColor:[UIColor redColor]];

    }

    - (void)doubleTap:(UIGestureRecognizer*)gestureRecognizer

    {

        [self.view setBackgroundColor:[UIColor blueColor]];

        NSLog(@"-----doubleTap-----");

    }

     
  • 相关阅读:
    题解 CF36B【Fractal】
    21清北学堂腾飞营游记
    canvas小试牛刀
    ES度量聚合(ElasticSearch Metric Aggregations)总结
    Mybatis中设计模式的运用
    Mybatis源码-SqlSession(二)
    Mybatis源码-sqlSessionFactory(一)
    Redis6.0多线程模型总结
    RocketMQ中的CommitLog、ConsumeQueue、indexFile、offsetTable以及多种偏移量对比
    SpringBoot——自动配置原理
  • 原文地址:https://www.cnblogs.com/nngh/p/4897607.html
Copyright © 2020-2023  润新知