容器视图控制器示例

时间:2011-10-13 14:14:59

标签: objective-c ios uiviewcontroller ios5

有人能指出我创建自定义视图控制器作为容器视图控制器的任何好例子吗?我能找到的唯一文件是UIViewController Class Reference中的几段。我觉得我需要比这更多的信息,一个示例实现会很好。谷歌几乎什么都没有发现。

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

transitionFromViewController:toViewController:duration:options:animations:completion:

7 个答案:

答案 0 :(得分:51)

到目前为止,我发现的最好的事情是WWDC 2011 Session Video Session 102 - Implementing UIViewController Containment

答案 1 :(得分:37)

答案 2 :(得分:17)

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

此IBAction触发两个VC之间的转换:

-(IBAction)button:(id)sender {
    [self transitionFromViewController:vc1 
                      toViewController:vc2 
                              duration:0.5    
                               options:UIViewAnimationOptionTransitionCurlDown 
                            animations:nil 
                            completion:nil];
}

答案 3 :(得分:11)

答案 4 :(得分:10)

答案 5 :(得分:8)

不知道这是否是一个“好”的例子,但你可以从https://bitbucket.org/javieralonso/jaacordeonviewcontroller/overview

获得一个免费的Container ViewController

这是一个完整的手风琴隐喻容器视图控制器

答案 6 :(得分:3)

这些是我最喜欢的(iOS7就绪)教程/关于这个主题的例子(这三个都在github上提供了源代码):

View Controller Containment

Custom Container View Controller Transitions

Interactive Custom Container View Controller Transitions

然后,当然,Apple提供了关于这个主题的全文,我发现这些内容非常宝贵:

Creating Custom Container View Controllers