UIViewControllers中的UIViewController

时间:2015-08-28 12:17:13

标签: ios swift uiviewcontroller uitabbar uitabbaritem

我有一个UITabConar,里面有UITabBar。我想模仿一个UITabBarController。

我的问题是,每当选择TabBarItem时,我该如何设置或UIViewController?

我很困惑如何将UIViewController放入我试图模仿UITabBarController的UIViewController中。

请不要让我使用UITabBarController

2 个答案:

答案 0 :(得分:1)

您可以使用子视图控制器在其他视图控制器中嵌入视图控制器,只需从视图控制器中调用它:

YourViewController *childViewController = [[YourViewController alloc] init];

UIView *containerView = //some view in your view hierarchy
childViewController.view.frame = containerView.bounds;

[self addChildViewController: childViewController];
[containerView addSubview:childViewController.view];
[childViewController didMoveToParentViewController:self];

如果要在子视图控制器之间进行分页,可以使用UIPageViewController作为根子视图控制器,或者从apple documentation:

借用此代码
- (void) cycleFromViewController: (UIViewController*) oldC
        toViewController: (UIViewController*) newC {

[oldC willMoveToParentViewController:nil];                        // 1
[self addChildViewController:newC];

newC.view.frame = [self newViewStartFrame];                       // 2
CGRect endFrame = [self oldViewEndFrame];

[self transitionFromViewController: oldC toViewController: newC   // 3
      duration: 0.25 options:0
      animations:^{
         newC.view.frame = oldC.view.frame;                       // 4
         oldC.view.frame = endFrame;
       }
       completion:^(BOOL finished) {
         [oldC removeFromParentViewController];                   // 5
         [newC didMoveToParentViewController:self];
        }];
}

答案 1 :(得分:1)