2015-07-02 96 views

回答

2
func handleTap(sender:UITapGestureRecognizer) { 
    if let tag = sender.view?.tag { 
     println(tag) 
    } 
} 
1

請嘗試下面的代碼。

override func viewDidAppear(animated: Bool) { 
     super.viewDidAppear(animated) 
     self.view.userInteractionEnabled = true 
     var tapGesture = UITapGestureRecognizer(target: self, action: Selector("handleTap:")) 
     self.view.tag = 101 
     self.view.addGestureRecognizer(tapGesture) 
    } 

    func handleTap(sender:UITapGestureRecognizer) { 
     if let tag = sender.view?.tag { 
      println(tag) 
     } 
    }