【问题标题】:Child view controller being partially shown under parent view controller's navigation bar [duplicate]子视图控制器部分显示在父视图控制器的导航栏下[重复]
【发布时间】:2013-09-20 10:17:59
【问题描述】:

在 ios7 上运行我的应用程序时,我注意到我的子视图控制器有一个起始点,它在其父视图控制器的导航栏下开始,而在 ios6 上却不是这样。

这是我在添加子视图控制器时使用的代码:

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    if (!self.selectionBarViewController) //self.selectionBarViewController is the child view controller
    {

        self.selectionBarViewController = [[UCIScrollSelectionBarViewController alloc] init];

        self.selectionBarViewController.view.frame = CGRectMake(0.0f,
                                                                0.0f,
                                                                self.view.frame.size.width,
                                                                44.0f);

        self.selectionBarViewController.dataSource = self;
        self.selectionBarViewController.delegate = self;

        [self addChildViewController:self.selectionBarViewController];
        [self.view addSubview:self.selectionBarViewController.view];
        [self.selectionBarViewController didMoveToParentViewController:self];

        [self.selectionBarViewController beginAppearanceTransition:YES
                                                          animated:YES];

    }

    //More set up code here

}

当我调整子视图控制器的框架时,我可以看到它,但理想情况下,如果用户从 iOS 6 或 7 运行应用程序,我不希望有条件布局代码。

【问题讨论】:

    标签: ios layout containers viewcontroller childviewcontroller


    【解决方案1】:

    原因很简单:导航栏的translucent属性的默认值。

    在 iOS 6.1 之前,默认值为 NO,但从 iOS7 开始,默认值为 YES。

    半透明导航栏仅位于其顶视图控制器的视图之上,而非半透明的导航栏会导致视图控制器的视图相应地调整大小。

    要回答您的问题,您可以手动设置navigationBar.translucent = NO,或者,如果您想让它保持半透明,您需要相应地调整布局。

    【讨论】:

    • 感谢 micantox,效果很好
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    • 1970-01-01
    • 2017-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多