iOS给UIView添加点击事件

前端之家收集整理的这篇文章主要介绍了iOS给UIView添加点击事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

  我要给一个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];

猜你在找的iOS相关文章