views:

30

answers:

1

Is it possible to detect the touches in a scrollview which is filled with a grid of buttons as in the image below?

alt text

For example, in this image, i can only drag the scroll view by dragging on the red areas, but i would like to be able to scroll the scrollview no matter where it is touched (like the iPhone's home screen)?

Thanks

A: 

Yes, this is absolutely possible. Ironically enough, I had to do this last night. In my case, I was embedding a UIView inside a UIScrollView, but I still wanted to detect taps and presses on my embedded view. To do this, I enabled user interaction on the UIView and then attached a UITapGestureRecognizer and a UILongPressGestureRecognizer to it. It works beautifully. :)

Dave DeLong
So, since my buttons are UIButtons, and they are subclasses of UIView which have interaction enabled by default, i need to attach a TapRecognizer to each button to detect the taps and the LongPress to the scrollview? Or is the LongPress to the button as well? Thanks
joec
It's possible that the UIButtons will work as-is. If they don't, there are several ways around this (such as attaching a UIGR to the superview, disabling interaction on the buttons, and then using the hitTest: method to identify which button and alter it appropriately)
Dave DeLong
I think the buttons work fine now. My issue is going to be scrolling the scrollview. Do i add the long press to the scrollview or the button?
joec
@joec my longpressGR was so I could detect a long press on one of my buttons (different from a tap). Unless you also need the same functionality, you don't need that GR.
Dave DeLong
Ah ok, well i dont need that functionality. Were you able to detect the scrollview drags without doing anything?
joec
@joec yep (6chars)
Dave DeLong
I see i asked if it was possible. I must be missing something then for mine not to work?
joec