Skip to content

Instantly share code, notes, and snippets.

@edom18
Last active October 18, 2015 19:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edom18/9200218 to your computer and use it in GitHub Desktop.
Save edom18/9200218 to your computer and use it in GitHub Desktop.
カスタムContainer View Controllerを作る ref: http://qiita.com/edo_m18/items/8b6b457f82b185ab1f6a
- (void)displayContentController:(UIViewController *)content
{
// 自身のビューコントローラ階層に追加
// 自動的に子ViewControllerの`willMoveToParentViewController:`メソッドが呼ばれる
[self addChildViewController:content];
// 子ViewControllerの`view`を自身の`view`階層に追加
[self.view addSubview:content.view];
// 子ViewControllerに追加が終わったことを通知する
[content didMoveToParentViewController:self];
}
- (void)hideContentController:(UIViewController *)content
{
// これから取り除かれようとしていることを通知する(引数が`nil`なことに注意)
[content willMoveToParentViewController:nil];
// 子ViewControllerの`view`を取り除く
[content.view removeFromSuperview];
// 子ViewControllerを取り除く
// 自動的に`didMoveToParentViewController:`が呼ばれる
[content removeFromParentViewController];
}
- (void)cycleFromViewController:(UIViewController *)oldC toViewController:(UIViewController *)newC
{
// 古いViewControllerに取り除かれようとしていることを通知する
[oldC willMoveToParentViewController:nil];
CGFloat width = self.view.bounds.size.width;
CGFloat height = self.view.bounds.size.height;
// アニメーションスタート位置を画面下部にする
CGRect startFrame = CGRectMake(0, height, width, height);
[self addChildViewController:newC];
newC.view.frame = startFrame;
CGRect endFrame = CGRectMake(0, 100, width, height);
[self transitionFromViewController:oldC
toViewController:newC
duration:0.25
options:0
animations:^{
newC.view.frame = oldC.view.frame;
oldC.view.frame = endFrame;
}
completion:^(BOOL finished) {
[oldC removeFromParentViewController];
[newC didMoveToParentViewController:self];
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment