Last active
October 18, 2015 19:04
-
-
Save edom18/9200218 to your computer and use it in GitHub Desktop.
カスタムContainer View Controllerを作る ref: http://qiita.com/edo_m18/items/8b6b457f82b185ab1f6a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)displayContentController:(UIViewController *)content | |
{ | |
// 自身のビューコントローラ階層に追加 | |
// 自動的に子ViewControllerの`willMoveToParentViewController:`メソッドが呼ばれる | |
[self addChildViewController:content]; | |
// 子ViewControllerの`view`を自身の`view`階層に追加 | |
[self.view addSubview:content.view]; | |
// 子ViewControllerに追加が終わったことを通知する | |
[content didMoveToParentViewController:self]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)hideContentController:(UIViewController *)content | |
{ | |
// これから取り除かれようとしていることを通知する(引数が`nil`なことに注意) | |
[content willMoveToParentViewController:nil]; | |
// 子ViewControllerの`view`を取り除く | |
[content.view removeFromSuperview]; | |
// 子ViewControllerを取り除く | |
// 自動的に`didMoveToParentViewController:`が呼ばれる | |
[content removeFromParentViewController]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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