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
Container View Controller Examples
提问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 JosephH
In addition to the WWDC Session Video Session 102 - Implementing UIViewController Containmentthat 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:
除了超加密已经提到的 WWDC Session Video Session 102 - Implementing UIViewController Containment之外,Apple WWDC 2012 会议“iOS 上的视图控制器的演变”也涵盖了这个主题,示例代码是示例代码包的一部分:
There's also an example here: https://github.com/toolmanGitHub/stackedViewControllers
这里还有一个例子:https: //github.com/toolmanGitHub/stackedViewControllers
回答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 Yuri Solodkin
I found this example very useful for me
我发现这个例子对我很有用
http://sandmoose.com/post/35714028270/storyboards-with-custom-container-view-controllers
http://sandmoose.com/post/35714028270/storyboards-with-custom-container-view-controllers
And they have source on github:
他们在 github 上有源代码:
回答by Rui Peres
Could this:
可以这样:
http://subjective-objective-c.blogspot.com/2011/08/writing-high-quality-view-controller.html
http://subjective-objective-c.blogspot.com/2011/08/writing-high-quality-view-controller.html
Be enough for your needs?
足以满足您的需求吗?
回答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 上提供了源代码):
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 提供了关于这个主题的完整文章,我认为这是非常宝贵的: