我正在实现自定义拖放,我想要的是创建单元格的副本(只是用于显示的图像)并且当此副本的位置与标题相同时,我想更改标题的背景颜色,如果该位置再次超出标题框架,则恢复他的背景颜色。
我坚持要确定正确的道路,到目前为止我得到了这个:
var draggedCellIndexPath: NSIndexPath?
var draggingView: UIView?
var sectionCell: UICollectionReusableView?
func handleLongPress(longPressRecognizer: UILongPressGestureRecognizer)
{
let touchLocation = longPressRecognizer.locationInView(self.collectionView)
switch (longPressRecognizer.state) {
case UIGestureRecognizerState.Began:
draggedCellIndexPath = self.collectionView!.indexPathForItemAtPoint(touchLocation)
break;
case UIGestureRecognizerState.Changed:
if draggedCellIndexPath != nil {
draggingView!.center = CGPoint(x: touchLocation.x + touchOffsetFromCenterOfCell!.x, y: touchLocation.y + touchOffsetFromCenterOfCell!.y)
if !isAutoScrolling {
let scroller = self.shouldAutoScroll(touchLocation)
if (scroller.shouldScroll) {
self.autoScroll(scroller.direction)
}
}
let currentTouchLocation = self.longPressRecognizer.locationInView(self.collectionView!.superview)
draggedCellIndexPathOnLocation = self.collectionView!.indexPathForItemAtPoint(currentTouchLocation)
let attributes = self.collectionView?.layoutAttributesForSupplementaryElementOfKind(UICollectionElementKindSectionHeader, atIndexPath: draggedCellIndexPathOnLocation!)
if draggedCellIndexPathOnLocation != nil
{
print("section \(draggedCellIndexPathOnLocation!.section)")
if attributes!.frame.intersects(draggingView!.bounds)
{
print("section number: \(draggedCellIndexPathOnLocation!.section)")
print("section is here")
}
break;
case UIGestureRecognizerState.Ended:
break;
default: ()
}
}
我在逻辑中缺少什么?