Detecting touches in subviews

Discussion in 'iOS Programming' started by John Baughman, Dec 26, 2010.

  1. John Baughman macrumors regular

    Oct 27, 2003
    I have a scroll view called bodyClockScrollView inside of which I put a UIView called bodyClock. In bodyClock I have drawn graphic and set viewForZoomingInScrollView to bodyClock. bodyClock with it's graphics scrolls and zooms perfectly inside the scroll view.

    I have several subViews that respond to touches. The touch delegate methods are implemented within these subclasses.

    If I add the touch subViews to the bodyClockScrollView the touches work, and the touch subViews scroll with the bodyClock. The touch subviews, however, do not zoom with the bodyClock.

    If I add the touch subViews to the bodyClock subview, everything including the touch subViews scroll and zoom properly. The touch subViews, however, no longer respond to touches.

    How can I get the touch subViews to both respond to touches and zoom properly. I thought I could move the touch delegate commands to the bodyClock subView, but I cannot get them to fire there either nor can I get them to work in the scrollView.
  2. John Baughman thread starter macrumors regular

    Oct 27, 2003
    Problem solved

    OK, I found my problem I had a subview acting as a time mask in bodyClockScrollView that I think was responding to touches. This became evident when I noticed that the touch subViews did not respond to touches while the mask was over them. Because the mask was a subview to the scroll view, it would move when zooming such that a touch subview in the bodyClock view would come out from underneath the mask and suddenly start working.

    Moving the mask from bodyClockScrollView view to the bodyClock subView along with the touch subviews fixed my problem. Now all the subviews scroll and zoom properly, and respond to touches.

Share This Page