UICollectionView中的UIViewController [英] UIViewController within UICollectionView
问题描述
我的应用中有一个全屏 UICollectionView
。它水平滚动,每个单元格填充集合视图的边界。集合视图由 UIViewController
管理。
I have a full-screen UICollectionView
in my app. It scrolls horizontally and each cell fills the collection view's bounds. The collection view is managed by a UIViewController
.
鉴于每个页面相当复杂,每个页面本身都需要由关联的 UIViewController管理
。 iOS 5支持视图控制器包含,因此当连接和分离视图时,子控制器应该接收适当的生命周期方法(例如 viewWillAppear:
等)。这与视图回收有多好?
Given that each "page" is reasonably complex, it makes sense for each page itself to be managed by an associated UIViewController
. iOS 5 has support for view controller containment, so that the child controllers should receive the appropriate lifecycle methods (e.g. viewWillAppear:
, etc) when views are attached and detached. How nicely would this play with view recycling?
从页面1滚动到2,将创建一个新视图(因为在触摸期间两者可能同时在屏幕上)。从页面2移动到3, UICollectionView
可以成功出列页面1的视图,但现在会发生什么?我会强制将视图插入视图控制器三吗?
Scrolling from page "1", to "2", a new view would be created (as both could be onscreen at the same time during the touch-down). Moving from page "2" to "3", the UICollectionView
could successfully dequeue the view for page "1", but what happens now? Would I forcefully insert the view into view controller three like so?
id cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ident" forIndexPath:indexPath];
UIViewController *child_controller = [self controllerAtIndexPath:indexPath];
[child_controller setView:cell];
// ... and so on
这感觉不对。但是,我无法想到在这种情况下正确重用视图的正确方法。我完全采取了错误的方法吗?
This feels wrong. However, I can't think of a correct way to reuse views correctly in this instance. Am I taking the wrong approach entirely?
推荐答案
我不认为 UICollectionView
b最适合您的任务。
喜欢 rob mayoff 说:你可以使用 UIPageViewController
。
另一个选项可以使用 UIScrollView
,包含3个子视图(上一个,当前的, 下一个)。并且您将能够轻松管理它的位置和滚动视图偏移以实现您想要的效果。
这在WWDC 2011中有描述'高级Scrollview技术'。你可以从那里获取源代码。
I don't think that UICollectionView
is the best choose for your task.
Like rob mayoff said: you can use UIPageViewController
.
Another option can be using UIScrollView
with 3 subviews (previous, current, next). And you will be able to easy manage it's position and scroll view offset to achieve effect that you want.
This is described in WWDC 2011 'Advanced Scrollview Techniques'. You can grab source code from there.
这篇关于UICollectionView中的UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!