IOS笔记 : addChildViewController

一下addChildViewController,一个ViewController可以添加多个子ViewController,但是这 些子ViewController只有一个是显示到父视图中的,可以通过transitionFromViewController:toViewController:duration:options:animations:completion:这个方法转换显示的子视图。同时加入相应的动画。

 //在parent view controller 中添加 child view controller
   FirstViewController *firstViewController=[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    [self addChildViewController:firstViewController];

    SecondViewController *secondViewController=[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    [self addChildViewController:secondViewController];

    ThirdViewController *thirdViewController=[[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
    [self addChildViewController:thirdViewController];

    [self.view  addSubview:thirdViewController.view];

  // addChildViewController回调用[child willMoveToParentViewController:self] ,但是不会调用didMoveToParentViewController,所以需要显示调用
    [thirdViewController didMoveToParentViewController:self];
    currentViewController=thirdViewController;

  //切换child view controller
     [self transitionFromViewController:currentViewController toViewController:firstViewController duration:4 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
            }  completion:^(BOOL finished) {
               //......
            }];
    currentViewController=firstViewController;

  //移除child view controller
    // removeFromParentViewController在移除child前不会调用[self willMoveToParentViewController:nil] ,所以需要显示调用
    [currentViewController willMoveToParentViewController:nil];
    [currentViewController removeFromSuperview];
    [currentViewController removeFromParentViewController];

  

时间: 2024-08-25 22:04:59

IOS笔记 : addChildViewController的相关文章

iOS笔记:Objective-C自定义NSLog宏

/*  XCode LLVM XXX - Preprocessing中Debug会添加 DEBUG=1 标志  */ #ifdef DEBUG #define NSLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORM

学习ios笔记第一天的C语言学习记录

c语言基础学习 int num1 = 15; int num2 = 5; int temp = 0; //先把num1放到temp里 temp = num1; //先把num2放到num1里 num1 = num2; //先把temp放到num2里 num2 = temp; 算数运算符 +加法运算 -减法运算符 *乘法运算符 /除法运算符  ------整型相除取整,除数不为0 %取余运算符 ------两边均为整数 ++递增运算-------运算符在前,先执行:运算符在后,后执行: --递减运

iOS 笔记-incompatible pointer types initializing 'NSMutableString *' with an expression of type 'NSString *'警告处理

记录下来,以防止再犯错 代码如下 NSString *userHeader = [userInfoDictionary objectForKey:@"photo"]; NSMutableString *mutableuserHeader = [NSMutableString stringWithString:userHeader]; //设置用户头像 NSRange range = [mutableuserHeader rangeOfString:@".."]; [

麦子学院ios笔记:IOS把图片缓存到本地的几种方法

把ios的图片缓存到本地的方法有几种?现在来看看学生在麦子学院学习ios开发的笔记中有讲到哪几种方法呢? <code>把图片缓存到本地,在很多场景都会用到,如果是只储存文字信息,那建一个plist文件,或者数据库就能很方便的解决问题,但是如果存图片到沙盒就没那么方便了.这里介绍两种保存图片到沙盒的方法. </code> 一.把图片转为base64的字符串存到数据库中或者plist文件中,然后用到的时候再取出来 <code class="hljs" obje

[iOS笔记]《编写高质量iOS与OS X代码的52个有效方法》:1.熟悉Objective-C

简介: 最近公司项目收尾,可以有时间看看书了.<编写高质量iOS与OS X代码的52个有效方法>这本书讲解了很多iOS开发的技巧和规范,大力推荐! 下面是自己看书时整理的笔记,照惯例先上目录: 目录: 第一章:熟悉Objective-C 第二章:Object.Message.Runtime 第三章:接口与API设计 第四章:Protocol与Category 第五章:内存管理 第六章:Block与GCD 第七章:系统框架 第一章    熟悉Objective-C 第1条:了解Objective

iOS笔记(常用的一些知识点)

这是我在公司做项目时,顺便做的一些笔记....... //1.iphone开发--改变UIPageControl里的小点的颜色 pageControl.currentPageIndicatorTintColor = [UIColor blackColor]; pageControl.pageIndicatorTintColor = [UIColor grayColor]; //2.ios如何让状态栏变成白色的 [[UIApplication sharedApplication]setStatus

麦子学院ios笔记:Objective-C 实现2048算法类

今天麦子学院ios开发老师给大家介绍Objective-C 实现的IOS版小游戏2048算法类,十分的实用,有需要的小伙伴可以参考下. 参数model有一个二维数组data,及阶数matrix // .h文件 @classDataModel; @interfaceAlgorithm : NSObject @property(nonatomic,assign)intaddScore;// 加分 - (void)caculateTop:(DataModel *)model;// 上滑规则 - (vo

034-iOS屏幕适配-iOS笔记

学习目标 1.[了解]屏幕适配的发展史 2.[了解]autoResizing基本用法 3.[掌握]autoLayout 的基本用法 4.[掌握]autoLayout代码实现 5.[理解]sizeClass的基本用法 一.屏幕适配的发展史 随着iOS屏幕尺寸越来越多样化,屏幕适配也就越来越重要了. iphone1 - iphone3gs时代,window的size固定为(320,480).我们只需要简单计算一下相对位置就好了,不需要做屏幕适配. iphone4 - iphone4s时代,苹果推出了

iOS笔记,开发经验总结【持续更新】

1. 设置navigationBar 背景颜色有色差, 原因:如果单纯的设置背景颜色也是有高斯模糊处理的效果,对纯色高斯模糊处理过后相当于纯色的70%(猜测)透明化处理,但是反正就是有色差 解决方法一: self.navigationController.navigationBar.translucent = NO;//    Bar的模糊效果,默认为YES 方法二: 通过图片方法 [self.navigationController.navigationBar setBackgroundIma