为什么缩放时会调整UIScrollView的contentSize?

mea*_*ers 5 objective-c uiscrollview uiscrollviewdelegate ios

在下面的代码中,我看到一个红色的正方形出现,可以滚动浏览(因为scrollview的内容是4x屏幕)。

但是,一旦我开始缩小(比例<1.0),滚动视图contentSize就会立即跳转到scaleiPad屏幕大小的几倍。例如:

0.985783 757.081249 1009.441665
Run Code Online (Sandbox Code Playgroud)

之后,我将无法再移动广场。当scaleget大于1.0 时,我只能移动正方形。在这种情况下,滚动指示器显示contentSize仍然是scale屏幕尺寸的乘积。

另一个效果是,当缩小到1.0以下时,红色方块通常会通过缩小移向左上角。但是,释放屏幕后(没有任何进一步的缩放),它甚至会移动到角落。编辑:这必须是滚动视图的橡皮筋。

(正方形本身确实按预期比例缩放。)

我在这里想念的是什么?这是我的视图控制器代码:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.scrollView                  = [[UIScrollView alloc]initWithFrame:self.view.bounds];
    self.scrollView.contentSize      = CGSizeMake(self.view.bounds.size.width * 2, self.view.bounds.size.height * 2);
    self.scrollView.backgroundColor  = [UIColor colorWithWhite:0.5f alpha:1.0f];
    self.scrollView.minimumZoomScale = 0.1f;
    self.scrollView.maximumZoomScale = 4.0f;
    self.scrollView.clipsToBounds    = YES;
    self.scrollView.delegate         = self;

    self.contentView = [[UIView alloc] initWithFrame:self.scrollView.bounds];
    [self.scrollView addSubview:self.contentView];
    [self.view addSubview:self.scrollView];

    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(400, 400, 100, 100)];
    view.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:view];
}

#pragma UIScrollViewDelegate

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

- (void)scrollViewDidEndZooming:(UIScrollView*)scrollView
                       withView:(UIView*)view
                        atScale:(double)scale
{
    NSLog(@"%f %f %f", scale, self.scrollView.contentSize.width, self.scrollView.contentSize.height);
}
Run Code Online (Sandbox Code Playgroud)