IOS开发--给UIImageView添加touch事件
2013-12-25 14:35
316 查看
IOS开发--给UIImageView添加touch事件
分类: IPhone开发中级系列2013-05-2917:25 942人阅读 评论(1) 收藏 举报UIImageViewtoucheeventIOSAdd Tap gesture
UITapGestureRecognizerto
myImageViewview
(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
imageViewClickedmethod, you can get the tapped ImageView using the
viewproperty 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 set
imageView.tag = indexPath.rowin
tableView: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开发中如何给UIImageView添加点击事件
- iOS:UIImageView添加点击事件
- iOS 给UIView、UIImageView、UILabel添加点击事件
- ios,swift 给控件(UIImageView,UIView,UILable)添加响应事件
- iOS UIImageView 添加 UITapGestureRecognizer 事件
- iOS-UIImageView添加事件
- iOS开发-UIImageView响应点击事件
- IOS开发:UIScrollView类介绍及如何简单地截获touch事件
- iphone开发笔记:为UIImageView添加点击事件
- iOS开发UI篇—在UIImageView中添加按钮以及Tag的参数说明
- iOS UIImageView图片添加点击事件
- IOS为UIImageView图片添加点击事件
- IOS开发之UI设计---视图交互与事件(UIButton,UIImage,UIImageView,UIController)
- iOS7开发:为UIImageView添加点击事件
- ios开发 UIView(UIImageView)添加六边形的遮罩
- iOS开发UI基础—13在UIImageView中添加按钮以及Tag的参数说明
- iOS开发UI篇—在UIImageView中添加按钮以及Tag的参数说明