我只是没有正确设置我的视图控制器。我将ViewController实现到另一个ViewController中,如下所示:
PARENT VIEWCONTROLLER:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self addTopTabBarController];
}
return self;
}
- (void)addTopTabBarController {
self.topTapController = [[TopBarViewController alloc] init];
[self addChildViewController:self.topTapController];
[self.topTapController didMoveToParentViewController:self];
[self.view addSubview:self.topTapController.view];
self.topTapController.view.frame = CGRectMake(0, 200, 320, 40);
}
儿童观看控制器
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Setup toolbar an set frame
self.toolbar = [[UIToolbar alloc] init];
NSLog(@"%f", self.view.frame.size.height);
}
return self;
}
当我记录frame.size.height时,我得到568.0作为返回值。为什么我没有返回40之前在父ViewController中设置?我退回了错误的财产吗?
答案 0 :(得分:1)
在NSLog
方法中尝试viewWillAppear
。
您只能在viewWillAppear