Container View Controller Examples
Solution 1
The best thing I have found so far is the WWDC 2011 Session Video Session 102 - Implementing UIViewController Containment.
Solution 2
In addition to the WWDC Session Video Session 102 - Implementing UIViewController Containment that hypercrypt already mentioned, Apple WWDC 2012 session on "The Evolution of View Controllers on iOS" also covers this topic and the example code is part of the sample code package:
There's also an example here: https://github.com/toolmanGitHub/stackedViewControllers
Solution 3
- (void)viewDidLoad{
[super viewDidLoad];
// I put self in a Navigation VC so we can use its right navigationbar
// item for triggering the transition
self.navigationItem.rightBarButtonItem =
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit
target:self
action:@selector(button:)]
autorelease];
// create test1 and test2 instance (subclass UIViewController and
// also need to define their own nibs)
vc1 = [[test1 alloc]initWithNibName:@"test1" bundle:nil];
vc2 = [[test2 alloc]initWithNibName:@"test2" bundle:nil];
//add to the container vc which is self
[self addChildViewController:vc1];
[self addChildViewController:vc2];
//the entry view (will be removed from it superview later by the api)
[self.view addSubview:vc1.view];
}
this IBAction triggers the transition between two VCs:
-(IBAction)button:(id)sender {
[self transitionFromViewController:vc1
toViewController:vc2
duration:0.5
options:UIViewAnimationOptionTransitionCurlDown
animations:nil
completion:nil];
}
Solution 4
I found this example very useful for me
http://sandmoose.com/post/35714028270/storyboards-with-custom-container-view-controllers
And they have source on github:
https://github.com/mluton/EmbeddedSwapping
Solution 5
Could this:
http://subjective-objective-c.blogspot.com/2011/08/writing-high-quality-view-controller.html
Be enough for your needs?
Undistraction
Updated on March 25, 2020Comments
-
Undistraction about 4 years
Can anyone point me to any good examples of creating a Custom View Controller as a Container View Controller? The only documentation I can find is a couple of paragraphs in the UIViewController Class Reference. I feel I need a little more information than that and an example implementation would be nice. Google has turned up nothing at all.
I am specifically interested in the method:
transitionFromViewController:toViewController:duration:options:animations:completion: