UIScrollView和zoomScale

时间:2012-10-31 14:27:43

标签: objective-c ios uiview uiscrollview

我有一个scrollView和两个子视图,其中包含一个imageView和一个按钮视图,其中包含一些热线,这些热点有图像视图的线条。我想放大/缩小并相应地移动热点。我遇到的问题是我无法将热点保留在我想要的地方,而且无法在这里找到解决方案。

这是我在viewDidLoad中的代码

- (void)viewDidLoad
{
    [super viewDidLoad];

    // set the tag for the image view
    [imageView setTag:ZOOM_VIEW_TAG];

    imageScrollView.delegate = self;

    float sexy = [imageScrollView frame].size.height  / [imageView frame].size.height;
    initialZoom = sexy;
    [imageScrollView setZoomScale:sexy animated:NO];
    [imageScrollView setMinimumZoomScale:sexy];
    [imageScrollView setContentInset:UIEdgeInsetsMake(-30, 0, 0, 0)];
    scaleStart =  imageScrollView.zoomScale;
    buttonView = [[UIView alloc]init];
    buttonView.frame = imageScrollView.frame;

    [imageScrollView addSubview:buttonView];

    button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button addTarget:self
               action:@selector(buttonClicked:)
     forControlEvents:UIControlEventTouchDown];
    [buttonView addSubview:button];

    [button setTitle:@"Button x" forState:UIControlStateNormal];

    button.frame = CGRectMake(200.0, 400.0, 520.0, 150.0);
    imageView.center = self.view.center;
    imageScrollView.maximumZoomScale = MAX_ZOOM_SCALE;

    //setting an orientation notifier
    UIDevice *device = [UIDevice currentDevice];                    //Get the device object
    [device beginGeneratingDeviceOrientationNotifications];         //Tell it to start monitoring the accelerometer for orientation
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];    //Get the notification centre for the app
    [nc addObserver:self                                            //Add yourself as an observer
           selector:@selector(orientationChanged:)
               name:UIDeviceOrientationDidChangeNotification
             object:device];    
  }

我试图在

中实现我的其余代码
- (void)scrollViewDidZoom:(UIScrollView *)aScrollView 

使用aScrollView.zoomScale属性没有任何运气。

并将按钮视图移动到正确的位置。我的问题是当我放大(完全放大)时缩放比例我得到0.53454的值,当我(完全)缩小我得到值0.37261为什么这发生了,我不再得到第一个值?

我该怎么做我想做的事?

我希望在放大/缩小时使用谷歌地图之类的东西,并且地点可以保持原位而不会自我缩放。

1 个答案:

答案 0 :(得分:0)

这个怎么样?

如果你想在缩放时保持自己的比例,你可以创建另一个包含它的视图。这就像将一个视图划分为两个视图一样。一个负责缩放,另一个负责处理保持规模的事情。这就是我做的原因。