How to have images that do not resize when zooming in a UIScrollView?
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 custom开发者_StackOverflowized 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?
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);
}
精彩评论