1

我有一个带有 frame (1000, 500) 和 contentSize (1000, 1500) 的垂直滚动滚动视图。这工作正常。但是,一旦我放大,它会将内容大小裁剪为我在缩放之前看到的任何内容,因此,我不能再垂直滚动超出原始范围。也就是说,如果我从默认视图缩放到 2 倍,它现在将 contentSize 报告为 (2000, 1000) 而不是预期的 (2000, 3000)。我无法滚动过去我正在查看的初始 (1000, 500) 矩形。当我缩小到 1 倍时,我仍然无法再垂直滚动;它将 contentSize 更改为 (1000, 500)。

我该如何解决?我不能在同一个 UIScrollView 中结合滚动和缩放吗?我尝试在缩放之前保存高度,然后在 didEndZooming 委托方法中更正 contentSize(contentSize = (width, savedHeight * scale)),但随后它显示了各种奇怪的行为,包括在着陆时跳来跳去。

这不应该开箱即用吗?我疯了吗?

- (void)createPage {
    self.fullWidthScroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,LANDSCAPE_WIDTH,LANDSCAPE_HEIGHT)];
    [self.view addSubview:self.fullWidthScroller];

    self.fullWidthScroller.contentSize = CGRectMake(0,0,LANDSCAPE_WIDTH,LANDSCAPE_HEIGHT*2);
    self.fullWidthScroller.delegate = self;
    self.fullWidthScroller.minimumZoomScale = 1.0;
    self.fullWidthScroller.maximumZoomScale = 3.0;
    self.fullWidthScroller.bouncesZoom = YES;

    self.container = [[UIView alloc] initWithFrame:CGRectMake(0,0,LANDSCAPE_WIDTH,LANDSCAPE_HEIGHT)];
    [self.fullWidthScroller addSubview:self.container];

    self.page = [[SinglePageViewStretched alloc] init];
    [self.container addSubview:self.page]; //container gets another view added elsewhere
}


- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return self.container;
}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale {
    NSLog(@"size: %@", NSStringFromCGSize(scrollView.contentSize));
    NSLog(@"offset: %@", NSStringFromCGPoint(scrollView.contentOffset));
    //scrollView.contentSize = CGSizeMake(scrollView.contentSize.width, self.contentSizeHeight * scale);
}
4

0 回答 0