layout icon indicating copy to clipboard operation
layout copied to clipboard

Long Press Gesture?

Open sidhenn opened this issue 6 years ago • 1 comments

I need to add a Long Press Gesture to an existing UICollectionView cell in Layout but having problems.

This is the extra code.

extension TimerCollectionViewController: UIGestureRecognizerDelegate
{
    @objc func onDidLongPressTimer(gestureRecognizer : UILongPressGestureRecognizer)
    {
        if gestureRecognizer.state != UIGestureRecognizer.State.began { return }
        
        let p = gestureRecognizer.location(in: timerCollectionView)
        if let indexPath = timerCollectionView?.indexPathForItem(at: p)
        {
            print("\(indexPath.row) Let's delete this timer.")
        } else {
            print("got nothing...")
        }
    }
}

I also added the following to viewDidLoad()

// Add Long Press Gesture to delete
        let lpgr : UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(onDidLongPressTimer))
        lpgr.minimumPressDuration = 0.5
        lpgr.delegate = self
        lpgr.delaysTouchesBegan = true
        timerCollectionView?.addGestureRecognizer(lpgr)

sidhenn avatar Dec 16 '18 02:12 sidhenn

Anyone have thoughts on this. Not working using 0.6.35.

Thanks.

sidhenn avatar Jan 19 '19 17:01 sidhenn