导读
简单用Swift写了一个collectionview的拖拽点击排序效果;
拖拽排序是新闻类的App可以说是必有的交互设计,如今日头条,网易新闻等。
效果
主要代码
手势长按移动
1.给CollectionViewCell添加一个长按手势.
private lazy var collectionView: UICollectionView = {
let clv = UICollectionView(frame: self.view.frame, collectionViewLayout: ChannelViewLayout())
clv.backgroundColor = UIColor.white
clv.delegate = self
clv.dataSource = self
clv.register(ChannelViewCell.self, forCellWithReuseIdentifier: ChannelViewCellIdentifier)
clv.register(ChannelHeaderView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: ChannelViewHeaderIdentifier)
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(longPressGesture(_:)))
clv.addGestureRecognizer(longPress)
r