在我的项目中,我有一个 UITableView,它包含水平滚动的 UICollectionViews。因此 TableView 中的每个单元格都是一个新的 Collection View 。我需要在每个单元格的左侧有一个交互式 View 。该 View 将沿左侧折叠,但如果您点击该 View ,它会以动画方式打开一点。如果 Collection View 一直滚动到左侧(即开头),它将打开。一旦用户开始滚动 Collection View ,它就会自动关闭。
这是一个直观的示例:
表格 View 单元格..
The view is collapsed in this image.
____________________________
|V | |
|i | CollectionView |
|e | Scrolls </> |
|w_|_______________________|
The view is open in this image. The ways it opens are described above.
____________________________
|V | |
|i | CollectionView |
|e | Scrolls </> |
|w______|__________________|
如何才能让这个交互式 Controller 位于我的单元格的左侧,其中已经有 Collection View ?
此外,如果有任何第三方控件可以实现类似的功能,那就太好了!
最佳答案
这将是一个 UIView
- 而不是 UIViewController
- 放置在 UICollectionView
的左侧。
在 UICollectionView
委托(delegate)方法 cellForItemAtIndexPath
中,只要第一个 Collection View 单元格可见,您就可以展开和缩回 cellLeftSideView
:
if ([[cell_CollectionView indexPathsForVisibleItems] containsObject:[NSIndexPath indexPathForItem:0 inSection:0]]) {
// First item IS showing in collection view
// Make sure left side view is expanded
[UIView animateWithDuration:0.5 animations:^{
CGRect aFrame = cell_LeftSideView.frame;
aFrame.size.width = kCellLeftSideView_Width_Max; // <= #define maximum width value
cell_LeftSideView.frame = aFrame;
}];
}
else
{
// First item is NOT showing in collection view
// Make sure left side view is shrunk
[UIView animateWithDuration:0.5 animations:^{
CGRect aFrame = cell_LeftSideView.frame;
aFrame.size.width = kCellLeftSideView_Width_Min; // <= #define minimum width value
cell_LeftSideView.frame = aFrame;
}];
}
关于ios - 如何在 UITableViewCell 中添加交互式 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19216019/