Created
January 14, 2016 22:31
-
-
Save xyclos/5b88686090bc581fc942 to your computer and use it in GitHub Desktop.
Add tap gesture recognizer to image view.
This file contains 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
import UIKit | |
class ViewController: UIViewController { | |
var imageView: UIImageView? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let screenSize: CGRect = UIScreen.mainScreen().bounds | |
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("imageTapped")) | |
if let image = UIImage(named: "autumn.jpg") { | |
imageView = UIImageView(image: image) | |
imageView!.frame = screenSize | |
imageView!.userInteractionEnabled = true | |
imageView!.addGestureRecognizer(tapGestureRecognizer) | |
view.addSubview(imageView!) | |
} | |
} | |
func imageTapped() { | |
print("image tapped") | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment