美文网首页
创建父子控制器

创建父子控制器

作者: 王小宾 | 来源:发表于2016-05-25 15:57 被阅读67次

建立父子关系后,容器设置子视图控制器的视图大小,并且把它添加到自己的视图层级关系中。设定子视图控制器的视图大小是很重要的,确保视图正确显示在父控制器的视图中。添加视图后,父控制器调用子视图控制器的didMoveToParentViewController:方法,父视图控制器给孩子一个机会来响应视图所属关系的改变。

//添加子控制器
- (void)displayContentController:(UIViewController*)content contentFrame:(CGRect)frame {

    [self addChildViewController:content];
    content.view.frame = frame;
    [self.view addSubview:content.view];
    [content didMoveToParentViewController:self];

}
//移除子控制器
- (void) hideContentController: (UIViewController*) content {

[content willMoveToParentViewController:nil];
[content.view removeFromSuperview];
[content removeFromParentViewController];

}
//子控制器之间的切换
- (void)cycleFromViewController: (UIViewController*) oldVC
               toViewController: (UIViewController*) newVC {
    // Prepare the two view controllers for the change.
    [oldVC willMoveToParentViewController:nil];
    [self addChildViewController:newVC];
    
    // Get the start frame of the new view controller and the end frame
    // for the old view controller. Both rectangles are offscreen.
    newVC.view.frame = CGRectMake(100, 200, 100, 100);
    CGRect endFrame = CGRectMake(200, 100, 100, 100);
    
    // Queue up the transition animation.
    [self transitionFromViewController: oldVC toViewController: newVC
                              duration: 1.25 options:UIViewAnimationOptionCurveEaseIn
                            animations:^{
                                // Animate the views to their final positions.
                                newVC.view.frame = oldVC.view.frame;
                                oldVC.view.frame = endFrame;
                            }
                            completion:^(BOOL finished) {
                                // Remove the old view controller and send the final
                                // notification to the new view controller.
                                [oldVC removeFromParentViewController];
                                [newVC didMoveToParentViewController:self];
                            }];
}

相关文章

  • 创建父子控制器

    建立父子关系后,容器设置子视图控制器的视图大小,并且把它添加到自己的视图层级关系中。设定子视图控制器的视图大小是很...

  • 父子控制器相关

    父子控制器:导航控制器,UITabBarViewController等。 父子控制器的设计原理:a控制器的View...

  • 父子控制器相关

    父子控制器相关 控制器父子关系的建立原则 如果2个控制器的view是父子关系(不管是直接还是间接的父子关系),那么...

  • 父子控制器

    父子控制器的小tips 控制器父子关系的建立原则 如果两个控制器的view是父子关系(不管直接还是间接的父子关系)...

  • 父子控制器详细解析

    父子控制器详细解析(一)父子控制器详细解析(二) —— 添加视图的层级问题

  • 父子控件、static的作用

    控制器父子关系的建立原则 - 如果2个控制器的view是父子关系(不管是直接还是间接的父子关系),那么这2个控制器...

  • 父子控制器的重要性(2018-06-03)

    控制器父子关系建立的原则 如果2个控制器的view是父子关系(不管是直接还是间接的父子关系),那么这两个控制器也应...

  • iOS-父子控制器

    控制器父子关系的建立原则 如果2个控制器的view是父子关系(不管是直接还是间接的父子关系),那么这2个控制器也应...

  • 父子控制器

    控制器父子关系的建立原则 如果2个控制器的view是父子关系(不管是直接还是间接的父子关系),那么这2个控制器也应...

  • 浅说控制器父子关系及示例展示

    控制器父子关系的建立原则 如果2个控制器的view是父子关系(不管是直接还是间接的父子关系),那么这2个控制器也应...

网友评论

      本文标题:创建父子控制器

      本文链接:https://www.haomeiwen.com/subject/xystdttx.html