容器视图控制器示例

有没有人能给我提供一些创建自定义视图控制器作为容器视图控制器的好例子?我能找到的唯一文档是 类引用中的几个段落。我觉得我需要更多的信息,一个示例实现将是不错的。谷歌一无所获。

我对这种方法特别感兴趣:

transitionFromViewController:toViewController:duration:options:animations:completion:
91993 次浏览

The best thing I have found so far is the WWDC 2011 Session Video Session 102 - Implementing UIViewController Containment.

- (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];
}

don't know if this is a "good" example, but you can get a free Container ViewController from https://bitbucket.org/javieralonso/jaacordeonviewcontroller/overview

It's a full accordion metaphor container view controller

These are my favorite (iOS7-ready) tutorial / examples on the subject (all three have source code available on github):

View Controller Containment

Custom Container View Controller Transitions

Interactive Custom Container View Controller Transitions

And then, of course, Apple offers a whole write-up on the subject which I find invaluable:

Creating Custom Container View Controllers