开发者

how to get touch event on imageView of UITableViewCell?

I want to get notifications when user single tap or double tap on imageView of 开发者_如何学CUITableViewCell. I have been try to add a subview to imageView, and use touchesBegan:withEvent: in subview controller, but can't trigger the event I expected. How can I do the job ?


One more solution:

Add a category to UIImageView to handle touch events. And then send out a notification for each touch event and subscribe to notifications in the view controller (or cell controller).

If you are feeling frisky, you could also forward the method calls to the view controller.

Then enable touch events for the imageView of the cell:

[self setUserInteractionEnabled:YES];

Now all touches will be sent where you want to handle them, without subclassing. And it is re-usable.


In my project I have subclassed UIImageView to add user interaction, if it can be useful you can simply have a look at the Apple Sample Code, project "TapToZoom". In shorts, you have to enable user interaction, and only after that the UIImageView will start to answer to touches. This is done by setting userInteractionEnabled property:

[self setUserInteractionEnabled:YES];

then you can customize other touches property by, for example:

[self setMultipleTouchEnabled:YES];
twoFingerTapIsPossible = YES;

Otherwise, you could be implementing a sort of thumbnails view like the photo app, let's say. Depending on your objective, you can also think about using a UIButton, where you can set a background image. I have a project where I mimic the photo thumbnail view of the original photo app simply by putting programmatically four UIButtons in each tableView row, and it works fine. Cheers


Thanks for the answers above, the job has been done.

My solution: 
  subclass a UIView, override touchesBegan:withEvent: in it's implementation file
  add the UIView(as subview) to cell.view and cover the position of imageView, then make the subview nearest transparent(alpha=0.015f)
  done.
  it works fine

Note: if alpha number is too small(0.01f), there will not trigger the touch event, anybody knows why?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜