当前位置: 代码迷 >> 综合 >> iOS点击手势(tap)
  详细解决方案

iOS点击手势(tap)

热度:48   发布时间:2024-01-20 19:28:11.0


UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 100, 100, 100)];

UIImage *image = [UIImage imageNamed:@"1.png"];

imgView.image = image;

imgView.userInteractionEnabled = YES;


//第二步 添加手势

    //抽象类 特点 不能创建对象

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

    tap.delegate = self;

    //设置属性 点击此次 1单击 2双击

    tap.numberOfTapsRequired = 1;

    //设置属性 单击触控 还是多点触控

    tap.numberOfTouchesRequired = 1;

    [imgView addGestureRecognizer:tap];



#pragma mark - 点击手势触发事件

-(void)imageViewTap:(UITapGestureRecognizer *)tap

{

    NSLog(@"识别到了点击手势");

    self.view.backgroundColor = [UIColor greenColor];

}


  相关解决方案