Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long Press Gesture? #167

Open
sidhenn opened this issue Dec 16, 2018 · 1 comment
Open

Long Press Gesture? #167

sidhenn opened this issue Dec 16, 2018 · 1 comment

Comments

@sidhenn
Copy link
Contributor

sidhenn commented Dec 16, 2018

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
Copy link
Contributor Author

sidhenn commented Jan 19, 2019

Anyone have thoughts on this. Not working using 0.6.35.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant