views:

1512

answers:

2

I would like to use the scrolling/panning functionality of the UIScrollView but I would like to handle all the zooming and scaling myself. My current plan is to have a viewController that owns a UIView (I'll call it view1) with multiple UIViews and UIScrollViews as children.

Is it possible for view1 to handle all multi-touch events (in order to manually render all his children's zoomed states) and draw the results onto each respective scroll view to allow a user to scroll around the results?

(For the curious, the application is drawing multiple heatmaps, each with its own set of axes. While zooming or scrolling, the axes need to update themselves to correctly label the ranges represented in the data region (the scroll view). The reason I can't use the default context-image-scaling zoom that comes for free with the scrollView is that ANYthing drawn on the context zooms (including things like reference lines). The zooming action is not to actually make things bigger but to adjust the viewable data range.)

+2  A: 

You can indeed have the main hosting view intercept multitouch events and do scaling of the underlying UIViews programmatically. It's what I do in the OpenGL display portion of my application (source available here). You could still pass on single-touch events to the underlying scroll view for panning, etc.

However, there still might be a way to do what you describe without intercepting the touch events. UIScrollView does its default scaling by applying a transform to your content view. In response to this question, I describe a way to re-render your content view at the new scale once the pinch zooming has finished. This would let you refresh your drawing with sharp grid lines once the zoom is done.

Additionally, if you're not really scaling and you want to change another property of your view with the pinch zooming, you can do what I describe in that question and intercept the setting of the transform on your contentView, only don't apply the transform. You can extract the scale that the UIScrollView wants to set from that transform, and do your own custom redraw of the view in response.

Brad Larson
A: 

Thanks for your suggestion brad. the solution I ended up using was to extend UIScrollView and override the touchesMoved:withEvent: method with this:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    if ([[event touchesForView:self] count] == 1) 
         [super touchesMoved:touches withEvent:event];
    [content touchesMoved:touches withEvent:event];
}

where "content" is a pointer to my scrollview's content subview. I had to do it this way because my content needs to zoom-to-point (ie, the points in data-space under the user's fingers shouldn't change). The information sent to setTransform: can only tell me the size of the content frame, but I also need the offset into it.

zaccox