0

私の iPad アプリには、設定画面 (UIViewController サブクラス) があります。望ましい動作は、左側に UITableView があり、ユーザーがタップするセルに応じて右側に他の UIViewControllers をロードする iPad システム設定のようにすることです。

右側のペインに UINavigationController を使用せずにこれを行う方法がわかりません。右側にスタックを配置しても意味がありません。設定画面がルートコントローラーではないため、Split View を使用できません。

ストーリーボードでレイアウトしたView Controllerを使えるようにしたいです。実行時に設定詳細ビュー コントローラーのインスタンスを作成し、それらを子ビューとしてアタッチできることを Apple のドキュメントで確認しましたが、IB が提供する派手なレイアウト ツールをすべて失ってしまいました。私の設計チームは、これを開いて微調整できる必要があります。

カスタム セグエ (UIStoryboardSegue のサブクラス化) も試しましたが、プッシュ動作もしているようです。

これが私が現在持っているものの写真です。ナビゲーションコントローラーまたはスタックの動作なしでこれを行うにはどうすればよいですか? ここに画像の説明を入力

4

1 に答える 1

0

これは、UIViewController クラス リファレンスに記載されているカスタム コンテナー コントローラー API を使用して行うことができます。これを行う方法の例を次に示します。このコードは、コンテナー ビューを持つコントローラーにあります。IB では、シミュレートされたメトリクスでサイズを「フリーフォーム」に設定して代替コントローラーを作成し、ビューのサイズをコンテナー ビューに埋め込まれたコントローラーと一致するように変更しました (コンテナーはコンテナー ビューに対する IBOutlet です)。

- (void)viewDidLoad {
    [super viewDidLoad];
    self.initialVC = self.childViewControllers.lastObject;
    self.substituteVC = [self.storyboard instantiateViewControllerWithIdentifier:@"Substitute"];
    self.currentVC = self.initialVC;
}


-(IBAction)switchControllers:(UISegmentedControl *)sender {

    if (sender.selectedSegmentIndex == 0) {
        if (self.currentVC == self.substituteVC) {
            [self addChildViewController:self.initialVC];
            [self moveToNewController:self.initialVC];
        }
    }else{
        if (self.currentVC == self.initialVC) {
            [self addChildViewController:self.substituteVC];
            [self moveToNewController:self.substituteVC];
        }
    }
}


-(void)moveToNewController:(UIViewController *) newController {
    [self.currentVC willMoveToParentViewController:nil];
    
    [self transitionFromViewController:self.currentVC toViewController:newController duration:.6 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
        [self constrainViewEqual:newController.view];
    }
     
    completion:^(BOOL finished) {
        [self.currentVC removeFromParentViewController];
        [newController didMoveToParentViewController:self];
        self.currentVC = newController;
    }];
}


-(void)constrainViewEqual:(UIView *) view {
    [view setTranslatesAutoresizingMaskIntoConstraints:NO];
    NSLayoutConstraint *con1 = [NSLayoutConstraint constraintWithItem:self.container attribute:NSLayoutAttributeCenterX relatedBy:0 toItem:view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    NSLayoutConstraint *con2 = [NSLayoutConstraint constraintWithItem:self.container attribute:NSLayoutAttributeCenterY relatedBy:0 toItem:view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
    NSLayoutConstraint *con3 = [NSLayoutConstraint constraintWithItem:self.container attribute:NSLayoutAttributeWidth relatedBy:0 toItem:view attribute:NSLayoutAttributeWidth multiplier:1 constant:0];
    NSLayoutConstraint *con4 = [NSLayoutConstraint constraintWithItem:self.container attribute:NSLayoutAttributeHeight relatedBy:0 toItem:view attribute:NSLayoutAttributeHeight multiplier:1 constant:0];
    NSArray *constraints = @[con1,con2,con3,con4];
    [self.container addConstraints:constraints];
}
于 2013-05-06T20:26:11.567 に答える