我在我的应用程序中发现了一个奇怪的行为,其中IBOutlet
连接的视图在我的视图控制器调用viewWillAppear:
和viewDidAppear:
. 这是我的UIViewController
子类中的相关代码:
-(void)viewWillAppear:(BOOL)animated {
NSLog(@"%@", self.scrollView);
}
-(void)viewDidAppear:(BOOL)animated {
NSLog(@"%@", self.scrollView);
}
以及生成的日志输出:
MyApp[61880:c07] <UIScrollView: 0x1057eff0; frame = (0 0; 0 0); clipsToBounds = YES; autoresize = TM+BM; gestureRecognizers = <NSArray: 0x10580100>; layer = <CALayer: 0x1057f210>; contentOffset: {0, 0}>
MyApp[61880:c07] <UIScrollView: 0x1057eff0; frame = (0 44; 320 416); clipsToBounds = YES; autoresize = TM+BM; gestureRecognizers = <NSArray: 0x10580100>; layer = <CALayer: 0x1057f210>; contentOffset: {0, 0}>
这清楚地表明框架在两个调用之间发生了变化。我想用viewDidLoad
方法中的视图进行设置,但如果内容在屏幕上之前无法更改,那似乎毫无用处。会发生什么?