IOS筆記 : addChildViewController

來源:互聯網
上載者:User

標籤:blog   io   ar   os   sp   div   on   log   bs   

一下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];

  

IOS筆記 : addChildViewController

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.