iPhone: how do i redraw subviews while pinch zooming a uiscrollview
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 draw开发者_如何学Cing 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;
}
In >=3.2 there is now: - (void)scrollViewDidZoom:(UIScrollView *)scrollView
So some day in the future this will be the sensible solution to this.
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.
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.
精彩评论