ViewController的高度未正确设置

时间:2014-05-10 15:25:15

标签: ios uiviewcontroller

我只是没有正确设置我的视图控制器。我将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中设置?我退回了错误的财产吗?

1 个答案:

答案 0 :(得分:1)

NSLog方法中尝试viewWillAppear

您只能在viewWillAppear

获取视图的尺寸