0

Right now I have a longPressGesture on my collection view cell.

@IBAction func longGesture(sender: AnyObject) {


    if sender.state == UIGestureRecognizerState.Began
    {
        let location = sender.locationInView(sender.view)
        println(location)
        let index = whoCollectionView.indexPathForItemAtPoint(location)
        println(index)

    }

}

This is my code for the longPressGesture. I am getting good results on my location but for anything other then the last cell in the collectionView, I get nil for the index. On the last cell the index is 0.

I also tried replacing sender.view with self.view but that gives me weird results also. 60% of the long gestures I have return nil when I do this.

1 Answers1

0
 let location = sender.locationInView(sender.view)

the locationInView will need to be the collectionview, so that it can calculate using the cells frame.

Try

let location = sender.locationInView(whoCollectionView.view)
some_id
  • 29,466
  • 62
  • 182
  • 304