views:

935

answers:

3

I am developing an iPhone app that places multiple custom UIViews as subviews in a UIScrollView. The subviews are placed on top of each other as transparent views as each view has its own drawing routines that traces parts of the base view. The base view is a UIImageView that is typically a large image that I want the user to be able to pan and zoom in and out of.

The problem I am having is that when I zoom in and out of my UIScrollView, the subviews do not redraw themselves while the user is zooming. I can reposition and scale the subviews properly once the zoom is completed, but the user experience is less than desirable. I have not been able to find a way to either hide or redraw the subviews as the zoom is taking place to scale the subviews along with the ImageView.

Any ideas?

thanks!

Here is the code that I have implemented:

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {

 for (UIView *view in subViews)
 {
  [view updateView:scale];
 }
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *) scrollView {
 return imageView;
}
A: 

I don't know a proper way to implement it, but I have a work-around for you:

Since the viewForZoomingInScrollView is called right before the zooming and scrollViewDidEndZooming - right after, you could use the viewForZoomingInScrollView to call a method in a separate thread. That method will check the zoomScale of your UIScrollView each 100 milliseconds (or any other period that would look good) and will make all the needed changes. In scrollViewDidEndZooming you will stop the execution of the new method.

Michael Kessler
I tried this with a NSTimer instead of a thread, which I think is achieving the same thing. However, the performance is really bad in the simulator and makes the experience even worse. I think i'll just try and hide the subviews to see if that is a better experience.Perhaps I need to rethink how I'm designing the subviews and maybe just create a single view that handles all the rendering and detection of touch events.
Mike
A: 

In >=3.2 there is now: - (void)scrollViewDidZoom:(UIScrollView *)scrollView

So some day in the future this will be the sensible solution to this.

mclin
+1  A: 

The imageView that you are returning from viewForZoomingInScrollView: will be resized as the view zooms. You could implement setFrame: or the more standard layoutSubviews in that view to do your updating. The contentSize of the scroll view is also updated continually during zooming, so you could implement setContentSize: in a custom scroll view.

drawnonward