Search code examples
iphoneobjective-cuiscrollviewuiimageviewtouchesbegan

How to detect touch on UIImageView inside UIScrollview?


I have a UIScrollview in my app and I populate it with LOTS of UIImageViews approx 900. They are all very small and consist of only two different images over and over again.

Now I am having a lot of trouble detecting a touch on one of these UIImageViews.

I have assigned them all a unique TAG so as to be able to distinguish between them but I am really struggling to detect the touch.

The goal is just to be able to change the image of the touched UIImageView.

Due to the large amount of views involved a simple loop checking touch coordinates against each UIImageViews frame is just hanging my app.

Does anyone have any suggestions?

Thanks in Advance.

Ben


Solution

  • The best way to solve this issue is to subclass UIScrollView, add touchesBegan etc methods to it.

    @interface MyScroll : UIScrollView
     {
    
     }