カスタムドラッグアンドドロップを実装しています。セルのコピー(表示用の画像のみ)を作成し、このコピーの場所がヘッダーと同じ場合、ヘッダーの背景色を変更したい、場所が再びヘッダー フレームの外にある場合は、背景色を元に戻します。
私は正しいパスを決定するために立ち往生しています、私はこれまでにこれを得ました:
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: ()
}
}
ロジックに欠けているものは何ですか?