任何人都可以点我创建一个自定义视图控制器作为容器视图控制器的好例子吗?我能找到的唯一文档是UIViewController Class Reference中的几段。我觉得我需要比这更多的信息,并且示例实现会很好。 Google一无所有。容器视图控制器示例
我的方法特别感兴趣:
transitionFromViewController:toViewController:duration:options:animations:completion:
任何人都可以点我创建一个自定义视图控制器作为容器视图控制器的好例子吗?我能找到的唯一文档是UIViewController Class Reference中的几段。我觉得我需要比这更多的信息,并且示例实现会很好。 Google一无所有。容器视图控制器示例
我的方法特别感兴趣:
transitionFromViewController:toViewController:duration:options:animations:completion:
我迄今发现的最好的东西是WWDC 2011会议视频Session 102 - Implementing UIViewController Containment。
同上。这不是我最喜欢的演示代码示例,但它确实正确地实现了VC容器以及内存管理 - 当子视图控制器不再可见时,它们的发布非常重要。 – memmons
不幸的是,如何使用ContainerViewController的演示无法正常工作,因为他没有在他的iPad上设置电子邮件:-( –
该会话是否有代码示例? –
难道这:
http://subjective-objective-c.blogspot.com/2011/08/writing-high-quality-view-controller.html
足以满足您的需求?
其实我已经发现,但不幸的是它是关于Ios4写的,但是5已经做了重大改变。 Apple现在明确支持创建自定义视图控制器容器,尽管他们似乎不想帮助我们制定如何使用它们。不过谢谢。 – Undistraction
你能告诉我他们在哪儿说的吗?不要怀疑你,只是好奇,因为我也一直在努力。 – Peres
不用担心。我通过代码看他的容器类,其中没有使用任何下列方法:addChildViewController :, removeFromParentViewController, transitionFromViewController:toViewController:持续时间:选择:动画:完成:, willMoveToParentViewController:和 didMoveToParentViewController:里面全是在更新的UIViewController的ios5文档中提到。 – Undistraction
- (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为触发两个风投之间的过渡:
-(IBAction)button:(id)sender {
[self transitionFromViewController:vc1
toViewController:vc2
duration:0.5
options:UIViewAnimationOptionTransitionCurlDown
animations:nil
completion:nil];
}
这是一个很好的例子,但是这种情况下的内存管理可以改进:http://stackoverflow.com/a/8453677/849616更适合的解决方案 – Vive
不是说你' [self addChildViewController:vc1]; 没有意义。Container VC可能有多个Container View Controller。 –
@Vive我已经在我的项目中达到了一个关注内存管理的地步。我有什么特别的链接,你发布的内存管理更好?我是非常新的,很难看到差异es – jacobronniegeorge
不知道这是不是一个“好”的例子,但你可以从https://bitbucket.org/javieralonso/jaacordeonviewcontroller/overview
得到一个免费的集装箱的ViewController这是一个完整的手风琴隐喻容器视图控制器
很好找。这看起来很有用。 – Undistraction
除了WWDC会话视频Session 102 - Implementing UIViewController Containment高加密已经mentio斯内德,Apple WWDC 2012 session on "The Evolution of View Controllers on iOS"还涵盖了这个主题和示例代码示例代码包的一部分:
还有这里一个例子: https://github.com/toolmanGitHub/stackedViewControllers
+1提到哪里可以得到那该死的代码包。我一直在看它。 –
+1,为什么o苹果为什么不能在他们的成员页面上放置WWDC会话代码? – axello
+1,你介意共享,如何获得这个源代码路径? –
这是我最喜欢的(iOS7就绪)教程/关于这个问题的例子(所有三个都在GitHub上可用的源代码):
Custom Container View Controller Transitions
Interactive Custom Container View Controller Transitions
然后,当然,苹果提供了一个关于这个主题,我发现在整个写作有价值的:
你发现了一个比hypercrypt提到的这个以外的其他来源? –
还没有。如果我有时间,今天晚些时候我会再挖一次。看起来奇怪的是,由于它的重要性和实用性,它会有如此少的信息。我想知道它是否有问题,并且在改进后会有更好的记录。 – Undistraction
这让我非常困惑。例如,视图只能有一个嵌入式控制器。如果您想在该容器视图上切换控制器,那该怎么办? –