【问题标题】:iOS spacing issue with translucent navigation bar半透明导航栏的iOS间距问题
【发布时间】:2013-09-02 13:48:52
【问题描述】:

我目前有一个带有 3 段 UISegmentedControl 的 UIViewcontroller,单击该控制器时会显示切换视图控制器。这个视图的导航栏和标签栏是半透明的。

我这样初始化视图:

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setAutomaticallyAdjustsScrollViewInsets:YES];
    self.segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"View 1",@"View 2",@"View 3",nil]];
    [self.segControl setTintColor:[[ConstantsSingleton sharedConstants] default_bg_Color]];
    [self.segControl setSegmentedControlStyle:UISegmentedControlStyleBar];
    [self.segControl addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
    [self.segControl setSelectedSegmentIndex:0];
    self.navigationItem.titleView = self.segControl;

    //Setting up the first viewcontroller
    UIViewController *vc = [self viewControllerForSegmentIndex:self.segControl.selectedSegmentIndex];
    [self addChildViewController:vc];
    vc.view.frame = self.contentView.bounds;
    [self.contentView addSubview:vc.view];
    self.currentViewController = vc;
}

contentView 是一个 IB 定义的 UIView,前导和尾随为 0(所以基本上它填充了父视图)。

我通过以下方式切换视图控制器:

-(void)segmentChanged:(UISegmentedControl *)sender {
    UIViewController *vc = [self viewControllerForSegmentIndex:sender.selectedSegmentIndex];
    [self addChildViewController:vc];
    [self transitionFromViewController:self.currentViewController toViewController:vc duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
        vc.view.frame = self.contentView.bounds;
        [self.currentViewController.view removeFromSuperview];
        [self.contentView addSubview:vc.view];
    } completion:^(BOOL finished) {
        [vc didMoveToParentViewController:self];
        [self.currentViewController removeFromParentViewController];
        self.currentViewController = vc;
    }];
    self.navigationItem.title = vc.title;
}

现在,每当我使用不透明的导航栏和标签栏运行它时,它都可以正常工作,但是每当我尝试使用半透明的导航栏和/或标签栏时,只有第一个视图会调整大小/它的插图正确调整为不落后半透明的导航栏和/或标签栏。当它们出现在屏幕上时,第二个和第三个视图仍然会出现在它们的后面。 将哪个视图控制器设置为第一个视图控制器并不重要,都会导致相同的行为。

可能是什么导致了这个问题,有没有办法在不解决手动 contentinset 调整的情况下解决这个问题。

【问题讨论】:

    标签: iphone ios objective-c autolayout


    【解决方案1】:

    我建议在您查看的属性检查器中启用扩展边缘选项。

    【讨论】:

      【解决方案2】:

      这是一篇很好的 stackoverflow 帖子,用于区分 iOS 7 及更高版本的各种布局设置:

      Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多