わかりましたので、それが誰かを助けることができるなら、私はそれを行う方法を見つけました:
背景画像 (マップ) を使用して、scrollView にオーバーレイを追加しました。
+CustomScrollView
----> UIImageView (map)
----> OverlayImageView (overlay)
ズームするには、カスタム スクロールビューに次のメソッドを持つデリゲートが必要です。
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
//The background image with the map
return mapView;
}
//When a zoom occurs, move the overlay
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
UIImageView* overlayView = [scroll.subviews objectAtIndex:1];
float x;
float y;
float width;
float height;
//keep the width and height of the overlay
width = overlayView.frame.size.width;
height = overlayView.frame.size.height;
//Move it to stay over the same pixel of the map, and centers it
x = (self.overlay.point.x * scroll.zoomScale - width/2);
y = (self.overlay.point.y * scroll.zoomScale - height/2);
overlayView.frame = CGRectMake(x,y,width,height);
}
これにより、ズームは背景画像でのみ発生すると言われていますが、オーバーレイが にあるためUIScrollView
、一緒にパンします。scrollViewDidZoom
したがって、注意する必要があるのは、ズームが変更されたときにオーバーレイを移動することだけであり、メソッドでそれを知っています。
タッチ イベントを処理するために、touchEnded:withEvent:
ofをオーバーライドし、CustomScrollView
タップが 1 回しかない場合はそれをオーバーレイに転送します。タッチを処理するためにOverlayImageView
この同じメソッド ( ) をオーバーライドするだけなので、は表示しません。toucheEnded:withEvent:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch* touch = [touches anyObject];
// Coordinates in map view
CGPoint point = [touch locationInView:[self.subviews objectAtIndex:0]];
//forward
if(touch.tapCount == 1){
OverlayImageView* overlayView = [self.subviews objectAtIndex:1];
CGPoint newPoint = [touch locationInView:overlayView];
BOOL isInside = [overlayView pointInside:newPoint withEvent:event];
if(isInside){
[overlayView touchesEnded:touches withEvent:event];
}
}
// zoom
else if(touch.tapCount == 2){
if(self.zoomScale == self.maximumZoomScale){
[self setZoomScale:[self minimumZoomScale] animated:YES];
} else {
CGRect zoomRect = [self zoomRectForScrollView:self withScale:self.maximumZoomScale withCenter:point];
[self zoomToRect:zoomRect animated:YES];
//[self setZoomScale:[self maximumZoomScale] animated:YES];
}
[self setNeedsDisplay];
}
}
これが役立つことを願っています。