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, <