I am implementing a custom drag and drop, what i want is create a copy of the cell (just an image for the display) and when the location of this copy is the same that an header i want to change the background color of the header, and revert his background color if the location is out of the header frame again.
I am stuck to determine the right path, i got this so far :
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: ()
}
}
what am i missing in the logic?