我要给一个UIView对象topView添加点击事件,方法如下:
步骤1:创建手势响应函数
1 (void)event:(UITapGestureRecognizer *)gesture2 {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];