Xcode7 collectionView的编辑新特性

来源:互联网 发布:电脑设计软件培训 编辑:程序博客网 时间:2024/05/15 20:43

Xcode7更新后可以使用iOS9的系统,其中有一些新的特新,讲一下collectionView的移动过程.collectionView和tableView类似,但是以前并不具备移动功能.现在有了移动功能能更加方法的使用.
设置移动跟tableView的移动类似,只需要几个代理方法就可以实现.
demo在这里(免费的)http://download.csdn.net/detail/reikomiao/9196345

注意:前面的collectionView的基本设置,自定义cell就不赘述了,直接讲移动方法

1.打开编辑状态,下面表示全部都可以编辑

- (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath{    return YES;}

2.设置移动

- (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{    [self.collectionView moveItemAtIndexPath:sourceIndexPath toIndexPath:destinationIndexPath];    //当有数据的时候别忘了刷新数据    [self.collectionView reloadData]}

就这么简单就实现移动了.
移动的时候长按Item想拖哪拖哪.看图
原来是这样
这里写图片描述
移动一下
这里写图片描述
一定要是iOS9,Xcode7之前的根本打不出来这些方法.就酱紫,挺好玩的,我能自己拖一天.(:з」∠)

2 0
原创粉丝点击