gpt4 book ai didi

ios - UIViewController viewDidLayoutSubviews

转载 作者:行者123 更新时间:2023-12-01 19:23:32 27 4
gpt4 key购买 nike

我很难弄清楚为什么 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];
}

知道为什么吗?

最佳答案

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

改为这样做:

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

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

}

- (void)viewWillLayoutSubviews {
[ super View WillLayoutSubviews];

[自我 doSomeCustomLayoutStuff];
}

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

如果 (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);
}
}

关于ios - UIViewController viewDidLayoutSubviews,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9041386/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com