我有一个 UIScrollView 其中有一个 UIImageView.我想告诉脚上这个 imageView.当我增加销作为有关子视图处的 ImageView, 一切都是巨大的,除了当你放大规模转变发生在销。我不想要这种行为,并希望我的脚留相同。

所以我选择增加针对另一种观点,其坐在上面的图片视图,也是一个子视图的 UIScrollView.这里的想法如果你愿想象有一层其悬停在地图而不会规模尚未显示出针对我的情节。

销在加入层中看不卡尔如果 ImageView 尺度。然而,问题就变成位置的脚不匹配的原始来源的x/y的 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];

代码,以增加销后的一些事件。

[iconsView addSubview:pinIcon];

我被困在试图tp怎么得到我的脚悬停在地图上没有移动时的规模发生。

有帮助吗?

解决方案

我喜欢你的想法保持所有针图专门用于销(iconsView),但是我决定只增加它们作为有关子视图处为什么你被称为imageViewMap.

进口的QuartzCore.框架文件到项目中。

叫你的图控制器MyViewController.

#import <QuartzCore/QuartzCore.h>
@interface MyViewController : UIViewController <UIScrollViewDelegate>
@property (retain) UIScrollView *scrollView;
@property (retain) UIImageView *imageView;

//等

@implementation MyViewController

@synthesize scrollView;
@synthesize imageView;

我假设你有一个针图或图控制称为DropPinViewController.如果你只是使用的图像,可以一UIImageView,但我的脚有标签,所以我用一个xib。销应点到底中心的xib因为我们要去把锚点。

在你viewDidLoad你MyViewController,添加脚的风景如有关子视图处的图片视图.添加图片视图作为一个子视图的滚动型.设定的内容大小的滚动型.

scrollView.delegate = self;

使用这些委托方法:

- (void)scrollViewDidZoom:(UIScrollView *)aScrollView
{   
    for (UIView *dropPinView in imageView.subviews) {       
    CGRect oldFrame = dropPinView.frame;
    // 0.5 means the anchor is centered on the x axis. 1 means the anchor is at the bottom of the view. If you comment out this line, the pin's center will stay where it is regardless of how much you zoom. I have it so that the bottom of the pin stays fixed. This should help user RomeoF.
   [dropPinView.layer setAnchorPoint:CGPointMake(0.5, 1)];
    dropPinView.frame = oldFrame;
    // When you zoom in on scrollView, it gets a larger zoom scale value.
    // You transform the pin by scaling it by the inverse of this value.
    dropPinView.transform = CGAffineTransformMakeScale(1.0/scrollView.zoomScale, 1.0/scrollView.zoomScale);
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return imageView;
}

其他提示

所以有一件事我实现的,这还没解决我的问题,但我认为这是正确的道路是从这篇文章。

锚定)

我有我的观层次结构如下。

UIScrollView
 - UIImageView (map image)
 - IconsView (layer image to hold icons)

下一个步骤,我需要解决的是保持我的脚加入 IconsView 锚定在同一地点的当 UIImageView 正在放大和缩小。

我有一个循环,就通过我所有的脚,这是有关子视图处的 IconsView 和更新他们的原籍国和X和Y轴这是在 UIScrollView 代表们的 scrollViewDidScroll 法。

问题是这种技术已可怕的表现在设备上时,有一个很大的脚在地图上有太多的处理,需要发生。

一些建议:

1)中你会注意到,在谷歌地图应用程序,它限制销的数量,它试图显示默认。它只会显示的结果,最近的中心点,即如果有更多的可能的匹配。

2)你能简要隐藏的销过程中的任何滚动或捏行动,以便界面仍然响应和重新绘制它们的时刻的图像图停止移动。

3)如果必须显示大量的销和制作动画他们,你可能也看到使用CABasicAnimations动画脚和背景的同时,改变脚的位置,使用相同的数学,转变的背景规模。这可能顺利的显示器的扩散动更加顺畅运行他们在一个相当低的水平,而引入了其他挑战和限制。

http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/Animation_Types_Timing/Articles/PropertyAnimations.html#//apple_ref/doc/uid/TP40006672-SW1

Barney

我有同样的问题,我找到这个想法的手修正的销的位置不是很漂亮。然后,我不画出我的脚上的图返回的委托函数 viewForZoomingInScrollView: 和更新子视图(标记)的尺寸放大后已完成。

然而,就唠叨我这是能够在谷歌地图应用程序,但我不能重新创建它。

有一件事:任何人都可以解释我的行为exhibitet当我加入有关子视图处的UIScrollView不是'viewForZoomingInScrollView'..?例如:

UIImageView* marker = [[UIImageView alloc] initWithImage: myMarkerImage];
[marker setCenter: CGPointMake(250,150)];
[myScrollView addSubview: marker];

这似乎适用于最初的观点和时移动。放大时,这些有关子视图处不大小,这实际上是我们的目标,但问题是,所)框架来源的移动越滚动图中的一些相当奇怪的方式。看来,如果一个放大, marker.frame.size.origin 总是走向左上角(超景的(0,0)),创造人的印象是,我们实际上缩小了。这也是奇怪的,因为"缩小中心"始终应该在屏幕的中心,不是吗?好吧,我不得到它了。

撞击。;)

感谢大卫*布劳恩。你的代码工作除了一条线,我不得不发表评论。我的项目涉及具有UIScrollView,然后UIImageView上显示的地图,然后最后,针(按钮),代码的位置之后感双击的姿态。你的代码,我帮助账户的缩小规模。限制虽然是,当我捏缩小,每个脚没有"坚持"的具体一部分的图在哪里我的双挖掘。我无意中发现的解决方案,当我说出这一行:

//[dropPinView.层setAnchorPoint:CGPointMake(0.5,1)];

我没有完全理解,但我的代码现在工作!我希望其他人将受益于从我的经验。谢谢,大卫!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top