ios - 如何在 UITableViewCell 中添加交互式 View Controller ?

标签 ios objective-c uitableview

在我的项目中,我有一个 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/

相关文章:

ios - 以更简洁的方式在 Swift 中访问 JSON Key

ios - 如何将 UIImage 异步加载到 SwiftUI Image 中?

ios - 无法在 Xcode9 Swift4 中使用 alamofire 类和方法

iphone - 单击注释时如何将数据传递给它的 View Controller ?

objective-c - 从我的应用程序访问文档/收件箱中 IOS 上的文件

ios - 将2个阵列合并为一个阵列

ios - 在 cellForRowAtIndexPath 方法中设置自定义单元格的正确方法?

ios - ARC 不允许将非 Objective-C 指针类型 'int *' 隐式转换为 'Bird *'

ios - cellForRowAtIndex 自定义方法

ios - 如何使用 Swift 向 UITableView 添加项目?