容器视图控制器示例[关闭]

问题描述 投票:94回答:7

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

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

transitionFromViewController:toViewController:duration:options:animations:completion:
objective-c ios uiviewcontroller ios5
7个回答
51
投票

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



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



8
投票

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

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


3
投票

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

View Controller Containment

Custom Container View Controller Transitions

Interactive Custom Container View Controller Transitions

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

Creating Custom Container View Controllers

© www.soinside.com 2019 - 2024. All rights reserved.