Last active
August 29, 2015 14:15
-
-
Save claymcleod/b46a1c84e39cddc868e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Title: Listening for Tap Gestures | |
// Authors: Clay McLeod | |
// Description: How to handle tap gestures on a view controller. | |
// Section: Swift | |
// Subsection: UI | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Create TapGestureRecognizer to listen for taps | |
// target: Which class contains your callback? (self means to the same class) | |
// action: Name of the callback method | |
var tgr : UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "touchDidOccur:") | |
// Register our TapGestureRecognizer in our parent view | |
self.view.addGestureRecognizer(tgr) | |
... | |
} | |
... | |
func touchDidOccur(recognizer: UITapGestureRecognizer){ | |
// handle touch | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment