我有一个UIScrollView
其中有一个UIImageView
. 我想在这个上显示别针imageView
。当我将引脚添加为 的子视图时ImageView
,一切都很好,除了当您缩放时,引脚上也会发生比例变换。我不希望这种行为,并希望我的别针保持不变。
所以我选择将 Pin 图添加到位于 ImageView 顶部的另一个视图,也是UIScrollView
. 如果您可以想象,这里的想法是有一个悬停在地图上并且不会缩放但在我绘制它们的位置显示图钉的图层。
添加到图层视图时的图钉不会ImageView
缩放。然而,问题就变成了引脚的位置与原始原点 x/y 不匹配,因为ImageView
已经进行了比例变换。
基本上,这是一个带有 Pins 的地方的自定义地图。我试图让 Pins 浮在上面,而不是在我的 ImageView 上放大和缩小,但还记得在缩放发生时我放置它们的位置。
一些代码:
scrollView = [[UIScrollView alloc] initWithFrame:viewRect];
scrollView.delegate = self;
scrollView.pagingEnabled = NO;
scrollView.scrollsToTop = NO;
[scrollView setBackgroundColor:[UIColor clearColor]];
scrollView.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scrollView.bounces = YES;
scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
imageViewMap = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
imageViewMap.userInteractionEnabled = YES;
viewRect = CGRectMake(0,0,imageViewMap.image.size.width,imageViewMap.image.size.height);
//viewRect = CGRectMake(0,0,2976,3928);
[scrollView addSubview:imageViewMap];
[scrollView setContentSize:CGSizeMake(viewRect.size.width, viewRect.size.height)];
iconsView = [[UIView alloc] initWithFrame:imageViewMap.frame];
[scrollView addSubview:iconsView];
稍后在某些事件上添加 Pin 的代码。
[iconsView addSubview:pinIcon];
我一直在试图弄清楚如何让我的图钉在地图上悬停而不移动,当比例发生时。