1

我很难弄清楚为什么 Erica Sadun 在她的食谱示例 Ch07-11 中执行以下操作(在 viewDidLayoutSubviews 中调用 viewDidAppear)。也许这两种方法应该调用另一种方法?

见:https ://github.com/erica/iOS-5-Cookbook/tree/master/C07

- (void) viewDidAppear:(BOOL)animated
{
    scrollView.frame = self.view.bounds;
    scrollView.center = CGRectGetCenter(self.view.bounds);

    if (imageView.image)
    {
        float scalex = scrollView.frame.size.width / imageView.image.size.width;
        float scaley = scrollView.frame.size.height / imageView.image.size.height;
        scrollView.zoomScale = MIN(scalex, scaley);
        scrollView.minimumZoomScale = MIN(scalex, scaley);
    }
}

- (void) viewDidLayoutSubviews
{
    [self viewDidAppear:NO];
}

知道为什么吗?

4

2 回答 2

3

这对我来说似乎完全错误。当这些方法被调用时,让 UIKit 处理。

改为这样做:

- (void)viewDidAppear:(BOOL)animated {
    [超级 viewDidAppear:动画]; // 总是用 this 调用 super !!!

    [自我 doSomeCustomLayoutStuff]; // 我实际上并不认为这是必要的。viewWillLayoutSubviews 用于布置子视图,并在 iOS 5 及更高版本中自动调用。

}

- (void)viewWillLayoutSubviews {
    [超级视图WillLayoutSubviews];

    [自我 doSomeCustomLayoutStuff];
}

- (void)doSomeCustomLayoutStuff {
    scrollView.frame = self.view.bounds;
    scrollView.center = CGRectGetCenter(self.view.bounds);

    如果 (imageView.image)
    {
        浮动 scalex = scrollView.frame.size.width / imageView.image.size.width;
        float scaley = scrollView.frame.size.height / imageView.image.size.height;
        scrollView.zoomScale = MIN(scalex, scaley);
        scrollView.minimumZoomScale = MIN(scalex, scaley);
    }
}
于 2013-10-03T14:31:16.630 回答
0

因为 viewDidLayoutSubviews 中的布局 srollView 会更改您设置的滚动视图。然后,滚动滚动视图应该会有点卡顿。

于 2017-05-31T03:28:15.783 回答