容器视图控制器示例

发布于 2024-12-09 16:13:37 字数 1539 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

何处潇湘 2024-12-16 16:13:37

到目前为止,我发现的最好的东西是 WWDC 2011 会议视频 会议 102 - 实现 UIViewController Containment

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

愁杀 2024-12-16 16:13:37

除了 hypercrypt 已经提到的 WWDC 会议视频会议 102 - 实现 UIViewController Containment 之外,< a href="https://developer.apple.com/videos/wwdc/2012/">Apple WWDC 2012 会议“iOS 上视图控制器的演变”也涵盖了这个主题,示例代码是示例代码包的一部分:

https://developer.apple.com/devcenter/download.action?path=/wwdc_2012/wwdc_2012_sample_code/wwdc_2012_session_code.dmg

这里还有一个例子:
https://github.com/toolmanGitHub/stackedViewControllers

尾戒 2024-12-16 16:13:37
- (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];
}
- (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];
}
倦话 2024-12-16 16:13:37

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

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

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

养猫人 2024-12-16 16:13:37

这些是我最喜欢的(iOS7-ready)教程/示例(所有三个都在 github 上提供了源代码):

视图控制器包含

自定义容器视图控制器转换

交互式自定义容器视图控制器转换

然后,当然,Apple 提供了关于该主题的完整文章,我认为这非常有价值:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文