我要给一个UIView对象topView添加点击事件,方法如下:

步骤1:创建手势响应函数

1 (void)event:(UITapGestureRecognizer *)gesture
2 {
3     //处理事件  
4 }

步骤2:创建手势

1 UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(event:)];

步骤3:给View添加手势

1 //设置需要连续点击几次才响应,默认点击1次
2 [tapGesture setNumberOfTapsRequired:1];
3 
4 [topView addGestureRecognizer:tapGesture];

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-06
相关资源
相似解决方案