0

私は現在、UISegmentedControlクリックするとビューコントローラーが表示される3セグメントの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;
}

は、すべての側で先頭と末尾が 0 でcontentView定義された IB です(したがって、基本的には親ビューを埋めます)。UIView

次の方法でビューコントローラーを切り替えます。

-(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;
}

これで、不透明なナビゲーション バーとタブ バーを使用してこれを実行すると問題なく動作しますが、半透明のナビゲーション バーやタブ バーを使用しようとすると、最初のビューのみがサイズ変更され、そのインセットが半透明のナビゲーションの後ろにならないように適切に調整されますバーおよび/またはタブバー。2 番目と 3 番目のビューが画面に表示されると、それらの背後に表示されます。どのビューコントローラーが最初のビューコントローラーとして設定されているかは問題ではなく、すべて同じ動作になります。

何がこの問題を引き起こしている可能性がありますか?また、コンテンツ インセットを手動で調整せずにこれを解決する方法はありますか?

4

2 に答える 2

0

これは、iOS 7 以降のさまざまなレイアウト設定を区別する良いスタック オーバーフローの投稿です。

iOS7でのautomaticAdjustsScrollViewInsets、extendedLayoutIncludesOpaqueBars、edgesForExtendedLayoutの違いを説明

于 2014-11-17T20:17:42.280 に答える