关于iOS7中child viewController 的topLayoutGuide 的length错误的处理

很多人可能都遇到过这种问题:把一个TabBarController压栈到一个NavigationController中后,对TabBarController的视图控制器里的视图使用自动布局,当添加一个view.top = self.topLayoutGuide.bottom后,发现view一部分被NavigationBar挡住了。这是因为在is中,TabBarViewController里面的视图控制的的topLayoutGuide的length只有20个像素,处理方法是重载viewWillLayoutSubiews方法,改变约束的constant值,如下:

为了方便,我们不再添加view.top = self.topLayoutGuide.bottom的约束,而是添加view.top = self.topLayoutGuide.top的约束:

self.topLayoutGuideConstraint = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.topLayoutGuide attribute:NSLayoutAttributeTop multiplier:1 constant:0];
            [self.view addConstraint:self.topLayoutGuideConstraint];

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    self.topLayoutGuideConstraint.constant = [self.tabBarController.topLayoutGuide length];
}

在viewWillLayoutSubviews调用以后,tabBarController.topLayoutGuide的lenth是状态栏的高度和导航栏的高度之和


实际上不只是tabBarController存在这种问题,child viewController和  parent viewController之间也存在这种问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值