开发者

UIScrollView / UIView Zoom Problem

my application has a UIScrollView with a UIView as subview. Both are the same size. The scrollView contains a large image and the subview is a "overlay" view that holds markers that are set when the user taps at the large image (a map). It is basically a simple app that allows to set markers on certain locations on a map.

so far so good. Setting markers and scrolling the scrollView works (markers keep the position on the map). However, there is one problem left. When i zoom in/out, the markers (in the overlay view) are positioned incorrectly (the markers move to the upper left corner when i zoom in). I have already tr开发者_开发技巧ied to transform the marker positions using the convertPoint() method but unfortunatelly without success.

My UIView Hierarchy looks like this:

[mapScrollView addSubview:mapImageView]; // mapScrollView obviously is the scrollview. it holds
                                         // an UIView with an image (map).

[mapScrollView addSubview:mapImageAnnotationView]; // UIView that holds annotations (markers)

[mapImageView addGestureRecognizer:singleTap]; // handle taps
[mapImageView addGestureRecognizer:doubleTap];
[mapImageView addGestureRecognizer:twoFingerTap];

[self addSubview:mapScrollView]; // self is the container UIView that holds the composition

Size/bound setup:

mapImageView = [[UIImageView alloc] initWithImage: mapImage]; // init with image file
mapScrollView.contentSize = CGSizeMake(mapImageView.frame.size.width,mapImageView.frame.size.height);
mapScrollView.clipsToBounds = YES;

mapImageAnnotationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, mapImageViewWidth, mapImageViewWidth)];

can anybody point me into the right direction to fix this problem ?

thanks


Which view are you returning in the delegate method viewForZoomingInScrollView?

You should put your map and your overlays inside the same superview, add the super view into the scrollview and then return that superview in the delegate method

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜