我很难搞清楚为什么Erica Sadun在她的食谱例子Ch07-11中做了以下操作(在viewDidLayoutSubviews中调用viewDidAppear)。也许这两种方法应该调用另一种方法呢?UIViewController viewDidLayoutSubviews
请参见: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];
}
任何想法,为什么?
我想这只是不好的代码因子。她正在使用UIViewControllers系统调用viewDidAppear来执行初始布局,然后当视图完成布局子视图时,直接懒懒地重新使用相同的方法。我认为你的假设是正确的,viewDidAppear应该调用像'adjustView'这样的方法,viewDidLayoutSubviews也应该这样做。 – RLB 2012-01-28 17:09:08
我发现我可以将所有布局的东西放在viewDidLayoutSubviews中,并且它不需要处于viewDidAppear,viewWillAppear或甚至didRotateFromInterfaceOrientation中。 – 2013-09-30 14:55:05