ios 容器视图控制器示例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7755498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:51:31  来源:igfitidea点击:

Container View Controller Examples

objective-ciosuiviewcontrollerios5

提问by Undistraction

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.

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

I am specifically interested in the method:

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

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

采纳答案by hypercrypt

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

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

回答by sonnywang

- (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 触发了两个 VC 之间的转换:

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

回答by javieralog

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

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

It's a full accordion metaphor container view controller

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

回答by radiovisual

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

这些是我最喜欢的(iOS7-ready)教程/关于该主题的示例(所有三个都在 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:

然后,当然,Apple 提供了关于这个主题的完整文章,我认为这是非常宝贵的:

Creating Custom Container View Controllers

创建自定义容器视图控制器