如何在 UITableViewCell 中添加交互式视图控制器



在我的项目中,我有一个UITableView,它包含水平滚动的UICollectionViews。因此,表视图中的每个单元格都是一个新的集合视图。我需要在每个单元格的左侧有一个交互式视图。该视图将沿左侧折叠,但如果您点击该视图,它将以动画形式打开一点。如果集合视图一直向左滚动,即开头,它将打开。用户开始滚动集合视图后,它将自动关闭。

下面是一个可视化示例:

表视图单元格..

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______|__________________|   

我怎样才能在已经有集合视图的单元格左侧安装这个交互式控制器?

此外,如果有任何第三方控件可用于此类内容,那也很棒!

那将是一个UIView - 而不是一个UIViewController - 放置在UICollectionView的左侧。

UICollectionView delegate 方法中cellForItemAtIndexPath只要第一个集合视图单元格可见,您就可以展开和收回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;
    }];
}

最新更新