iOS 关于UITableView Group移动的那些事儿(tableview section move)

这篇博客主要介绍了在iOS应用中如何实现UITableView Section的移动,以达到分组排序的效果。作者分享了一位大神的思路,并在其基础上进行改进,解决了移动过程中保持数据结构完整的问题。文章提到了通过长按手势响应实现section移动,并使用Apple的API来确定点击的section。Demo包括了section的展开、移动、删除和添加等操作,提供了一种可能的解决方案。
摘要由CSDN通过智能技术生成

section的移动

github:https://github.com/Avanlanching/QJYTableViewSectionMove/tree/master/QJYTableViewSectionMove
具体的demo放在该路径下。
很多时候,我们都会遇到TableView cell 移动的问题,这个问题比较容易解决,apple官方给出了比较好的解决方案,iOS版的QQ也做了类似的方案。
这里分享一下以为大神的cell移动的方法,我也是从他的方法里面获取到的思路:http://blog.csdn.net/u012399689/article/details/45370567

在之前的项目里面有一个比较有趣的需求,在列表中去移动section,从而达到分组排序的效果。
这里与移动cell不同的是移动的过程中如何处理数据的问题。我这里是移动了section,在移动的同时还要保持结构完整。可以说,我在上面那位大神的基础上进行了改进。

- (void)longPressGestureRecognized:(UILongPressGestureRecognizer *)longPress {

    UIGestureRecognizerState state = longPress.state;
    CGPoint location = [longPress locationInView:self.tableView];

    // 判断长按手势的坐标落在哪一个section上面,如果不想写这个代码,可以将长按手势添加在section上
    NSIndexPath *indexPath = [self.tableView indexPathForSectionAtPoint:location numberOfSecton:self.dataArray.count];

    // 这里是快照 我们拖动不是真正的UITableViewHeaderFooterView 而是一张快照
    static UIView       *snapshot = nil;

    // 记录section的初始的行号
    static NSIndexPath  *initialLocation = nil;

    switch (state) {

        case UIGestureRecognizerStateBegan: {

            if (indexPath) {
                initialLocation = indexPath;
                self.moveSection = [self.tableView headerViewForSection:indexPath.section];

                // 创建section的一个快照
                snapshot = [self customSnapshoFromView:self.moveSection];

                // 添加快照至tableView中
                __block CGPoint center = self.moveSection.center;
                snapshot.center = center;
                snapshot.alpha = 0.0;
                [self.tableView addSubview:snapshot];

                // 按下的瞬间执行动画 这里最终目的是为了隐藏选中的Section
                [UIView animateWithDuration:0.25 animations:^{

                    center.y = location.y;
                    snapshot.center = center;

                    // 稍微设置一下快照的样式
                    snapshot.transform = CGAffineTransformMakeScale(1.05, <
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值