IOS开发--给UIImageView添加touch事件
来源:互联网 发布:mysql update语法 编辑:程序博客网 时间:2024/05/12 16:57
Add Tap gesture UITapGestureRecognizer
to myImageView
view (type of UIImageView
).
UITapGestureRecognizer *myTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureTapEvent:)]; myImageView.userInteractionEnabled = YES;[myImageView addGestureRecognizer:myTapGesture];[myTapGesture release];
Implement gestureTapEvent:
method to receive the touch event.
-(void)gestureTapEvent:(UITapGestureRecognizer *)gesture {
}UIImageView* myImageView = (UIImageView*)gesture.view ;
Then when you implement your
imageViewClicked
method, you can get the tapped ImageView using theview
property of the GestureRecognizer. Starting from that, you can for example:
- use the tag of your imageView (if you affected it in your
tableView:cellForRowAtIndexPath:
method) to retrieve the tag and do whatever you want with it (depending on what you affected it to, for example you may have setimageView.tag = indexPath.row
intableView:cellForRowAtIndexPath:
and get that indexPath row back then)- Go thru the superviews of the imageView up to the UITableViewCell, then ask for its indexPath to get it back and do whatever you want with it.
Example:
-(void)imageViewClicked:(UITapGestureRecognizer*)gestRecognizer{ UIImageView* iv = (UIImageView*)gestRecognizer.view; NSInteger tag = iv.tag; // then do what you want with this // or get the cell by going up thru the superviews until you find it UIView* cellView = iv; while(cellView && ![cellView isKindOfClass:[UITableViewCell class]]) cellView = cellView.superview; // go up until you find a cell // Then get its indexPath UITableViewCell* cell = (UITableViewCell*)cellView; NSIndexPath* indexPath = [self.tableView indexPathForCell:cell];}
- IOS开发--给UIImageView添加touch事件
- IOS开发--给UIImageView添加touch事件
- IOS开发--给UIImageView添加touch事件
- iOS 给UIView、UIImageView、UILabel添加点击事件
- ios,swift 给控件(UIImageView,UIView,UILable)添加响应事件
- 给UIImageView添加点击事件
- 给UIImageView添加点击事件
- 给UIImageView添加点击事件
- iOS-UIImageView添加事件
- iOS:UIImageView添加点击事件
- 给UIimageView添加UITapGestureRecognizer手势点击事件
- IOS界面开发给UIView添加事件
- iOS UIImageView图片添加点击事件
- iOS7开发:为UIImageView添加点击事件
- iOS开发-UIImageView响应点击事件
- sencha touch 给没有touch事件的控件添加touch事件
- UIImageView 添加事件
- UIimageView添加点击事件
- 安装Joomla后报错:Strict Standards
- android获得关于手机上的信息
- Android_XML文件解析
- 第一个自定义标签
- wpa_supplicant软件架构分析
- IOS开发--给UIImageView添加touch事件
- Objective-C 高级编程:iOS与OS X多线程和内存管理
- MySQL死锁问题实例分析及解决方法
- Java自学视频整理(持续更新中...)
- Linux rm命令 删除文件夹
- Awk 中变量作用域的问题
- 74个Android开发开源项目汇总<转载>
- C# 异常管理(一)
- VS2010运行速度优化汇总