Wie füge ich eine tap-Geste, um ein Bild mit swift

Ich weiß, das ist Recht einfach, ich fange mit swift und ich konnte Sie nicht finden, ein funktionierendes Beispiel.

Ich würde gerne auf ein Bild und eine Aktion. Das IBOutlet verbunden ist, um ein Bild auf der Haupt-Storyboard. Wenn ich Tippen Sie auf es, bekomme ich nichts. Ich hatte erwartet, um eine Konsole-Nachricht. Was mache ich falsch?

import UIKit

class FirstViewController: UIViewController {

    @IBOutlet weak var tapView: UIImageView!
    let tapRec = UITapGestureRecognizer()

    override func viewDidLoad() {
        super.viewDidLoad()
        //Do any additional setup after loading the view, typically from a nib.

        tapRec.addTarget(self, action: "tappedView")
        tapView.addGestureRecognizer(tapRec)

    }

    func tappedView(){
        println("image tapped")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        //Dispose of any resources that can be recreated.
    }


}
InformationsquelleAutor jackreichert | 2014-11-11
Schreibe einen Kommentar