我正在为我的应用程序使用xCode 6和大小类.
我遇到了一个我不明白的非常奇怪的问题.
我有一个在UIViewController中约束的UIView,我为Any x Any(150×150)大小的classe设置了宽度约束,为Regular x Regular(300×300)设置了另一个widh约束.
当我记录我的UIView的大小时,当应用程序在iPad上运行时,我遇到了问题.
实际上,在“viewWillAppear”,“viewWillLayoutSubviews”或“viewDidLayoutSubviews”中,我得到的尺寸为“150×150”而不是“300×300”.
我的日志:
- (void) viewWillAppear:(BOOL)animated { NSLog(@"viewWillAppear Size %f - %f",self.myView.frame.size.width,self.myView.frame.size.height); } - (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:YES]; NSLog(@"viewDidAppear Size %f - %f",self.myView.frame.size.height); } - (void) viewWillLayoutSubviews { [super viewWillLayoutSubviews]; NSLog(@"viewWillLayoutSubviews Size %f - %f",self.myView.frame.size.height); } - (void) viewDidLayoutSubviews { [super viewDidLayoutSubviews]; NSLog(@"viewDidLayoutSubviews Size %f - %f",self.myView.frame.size.height); }
我不明白的是,日志显示:
2015-02-17 09:29:38.984 myApp[660:42565] viewDidLoad Size 150.000000 - 150.000000 2015-02-17 09:29:38.985 myApp[660:42565] viewWillAppear Size 150.000000 - 150.000000 2015-02-17 09:29:39.047 myApp[660:42565] viewWillLayoutSubviews Size 150.000000 - 150.000000 2015-02-17 09:29:39.058 myApp[660:42565] viewDidLayoutSubviews Size 150.000000 - 150.000000 2015-02-17 09:29:39.063 myApp[660:42565] viewWillLayoutSubviews Size 230.000000 - 230.000000 2015-02-17 09:29:39.063 myApp[660:42565] viewDidLayoutSubviews Size 230.000000 - 230.000000 2015-02-17 09:29:39.586 myApp[660:42565] viewDidAppear Size 230.000000 - 230.000000 2015-02-17 09:29:39.591 myApp[660:42565] viewWillLayoutSubviews Size 230.000000 - 230.000000 2015-02-17 09:29:39.593 myApp[660:42565] viewDidLayoutSubviews Size 230.000000 - 230.000000
那么发生了什么?为什么我第一次得到Any x Any size class的大小?为什么这些方法被多次调用?
我看到我在viewDidAppear中有正确的帧大小,但我不喜欢它,因为有一个延迟beforc这个函数被调用. (我需要先用我的视图的框架大小做些什么来展示它….)