参考文章:http://www.cfanz.cn/index.php?c=article&a=read&id=53720
为UIView和子类添加点击事件,当然也可以用于 UIView 的子类,比如 UIImageview
主要三步:
self.tap=[[UITapGestureRecognizer alloc]initWithTarget:self actions:@selector(showLeftView)];//初始化手势 self.mainView.userInteractionEnabled=true;//设置可触摸 [self.mainView addGestureRecognizer:self.tap];//添加手势 //[self.mainView removeGestureRecognizer:self.tap];//移出手势 //如果方法是传的有参数,那么可以获取是哪个View触发了此方法: gesture.view ;
版权属于:东哥笔记 - DongGe.org
本文链接:https://dongge.org/blog/157.html
本文采用知识共享署名4.0 国际许可协议进行许可。转载或大段使用必须添加本文链接,否则您将构成侵权!