는 그래서, 그것을 할 수있는 방법을 발견했다.
확대하기 위해
+CustomScrollView
----> UIImageView (map)
----> OverlayImageView (overlay)
, 사용자 지정있는 ScrollView는 다음과 같은 방법으로 위임해야합니다 :이
- (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:
을 CustomScrollView
으로 대체하고 탭이 하나만있는 경우 오버레이로 전달합니다. 터치를 처리하기 위해 동일한 방법 (toucheEnded:withEvent:
) 만 덮어 쓰기 때문에 나는 OverlayImageView
을 표시하지 않습니다.
- (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];
}
}
희망이 도움이 될 것입니다.
더 많은 코드를 게시 할 수 있습니까? 나는 또한 이것을 얻으려고 노력하지만 할 수는 없다. – Devang