如何解决在 CollectionView 单元格之间拖动贝塞尔曲线
如果您在不可滚动的 collectionView Cell 内 touchDown,则应从那里画一条线到您移动手指的位置,直到您在另一个 collectionView Cell 内释放它 (touchUp)。然后该行应该正好在依赖单元格的中间开始和结束。
我创建了这个原型以便更好地理解:
这是我目前的代码:
import UIKit
class CVController: UIViewController,UICollectionViewDataSource,UICollectionViewDelegate {
let reuseIdentifier = "cell"
var items = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48"] //as test
func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int) -> Int {
return self.items.count
}
func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier,for: indexPath as IndexPath) as! MyCollectionViewCell
cell.myLabel.text = self.items[indexPath.row]
cell.backgroundColor = UIColor.cyan
return cell
}
func collectionView(_ collectionView: UICollectionView,didSelectItemAt indexPath: IndexPath) {
// handle tap events
print("You selected cell #\(indexPath.item)!")
}
func drawLine(start: CGPoint,end: CGPoint){
let path = UIBezierPath()
path.move(to: CGPoint(x: start.x,y: start.y))
path.addLine(to: CGPoint(x: end.x,y: end.y))
path.close()
UIColor.red.set()
path.lineWidth = 2
path.stroke()
}
}
有谁知道我如何实现它? 谢谢!!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。