views:

53

answers:

1

I want to have images inside of a UIScrollView (or at least appear to be inside a UIScrollView) that don't change their size when zooming in and out. I do want the images to maintain their positions when zooming or scrolling.

The use case is that I have a customized map view with pushpins. I want the pushpins to stay in place when zooming and scrolling the map, but I don't want them to be "zoomed in" with the content.

What is the best way to do this?

+1  A: 

You can have your pushpin image(s) as a subview of your UIScrollView but not a subview of the view returned by

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

Then, in scrollViewDidZoom adjust the pushpin x and y by the zoomScale to keep the pins correctly positioned:

- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
    imageView.frame = CGRectMake(pushPinX * scrollView.zoomScale, pushPinY * scrollView.zoomScale, imageView.frame.size.width, imageView.frame.size.height);
}
John N
This almost did it for me. Instead of repositioning my pins in scrollViewDidZoom I do it in scrollViewDidScroll which gets called continuously as view is zooming. Thanks for the tip!
Josh Knauer