zoukankan      html  css  js  c++  java
  • 单击双击手势(UITapGestureRecognizer)

    - (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-----");

    }

  • 相关阅读:
    sql查询
    PHP常用的设计模式
    PHP内存管理和垃圾回收机制
    记一次面试
    获取py文件函数名及动态调用
    正确解决 mysql 导出文件 分隔符 问题
    解决ValueError: cannot convert float NaN to integer
    Python ---接口返回值中文编码问题
    pandas python 读取大文件
    【neo4J】后台关闭后,前端还能打开视图
  • 原文地址:https://www.cnblogs.com/piaojin/p/5066083.html
Copyright © 2011-2022 走看看