Swift 3 – Press and LongPress

Here you have an example with a simple Tap and a long Tap.

    override func viewWillAppear(_ animated: Bool)

      let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tapped(_:) ))
      buttonTakeShare.addGestureRecognizer(tapGestureRecognizer)let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressed(_:)))


    func tapped(_ sender: UITapGestureRecognizer)

      print(“That is a simple tap”)


    func longPressed(_ sender: UITapGestureRecognizer)

      switch sender.state
      case UIGestureRecognizerState.ended:
      print(“Long Press Finished”)
      default: break


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s