English 中文(简体)
how to get touch event on imageView of UITableViewCell?
原标题:
  • 时间:2009-11-23 07:13:30
  •  标签:
  • iphone
  • touch

I want to get notifications when user single tap or double tap on imageView of UITableViewCell. 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 ?

最佳回答

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

问题回答

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.

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?





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签