放大UIScrollView更改(缩放比例)内容大小

时间:2013-08-06 16:46:16

标签: iphone ios objective-c cocoa uiscrollview

我有一个垂直滚动滚动视图,框架(1000,500)和contentSize(1000,1500)。这很好用。但是,一旦我放大,它就会将内容大小裁剪为我在缩放前看到的内容,因此,我无法再垂直滚动超过原始边界。也就是说,如果我从默认视图缩放到2x,它现在报告contentSize为(2000,1000)而不是预期的(2000,3000)。我不能滚过我正在看的那个初始(1000,500)矩形。当我缩小到1x时,我仍然不能再垂直滚动;它将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);
}

0 个答案:

没有答案