1
votes

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;
}
3
Make a UIView that contains the image, as well as all the other subviews, and in the viewForZoomingInScrollView method, return that parent view. All the subviews will be scaled while you zoom, haven't tested to see how well this works with text and complex views, just tried with rectangles. - Alex Gosselin

3 Answers

1
votes

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

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

1
votes

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.

0
votes

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.