2014-11-02 49 views
2

我在我的視圖控制器(通過故事板設置)中有一個UIImageView,我只是想知道如何在觸摸時解除它(這是一個'點擊開始'圖像)。Swift:Dismiss Image View

由於提前,

威廉

回答

1
class ViewController: UIViewController { 

    @IBOutlet weak var imageView: UIImageView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     // Enable user interaction with image 
     self.imageView.userInteractionEnabled = true 

     // Create a UITapGestureRecognizer 
     let gestureRecogniser = UITapGestureRecognizer(target: self, action: Selector("dismissImageView:")) 

     // Add the UITapGestureRecognizer to the image view 
     self.imageView.addGestureRecognizer(gestureRecogniser) 
    } 

    func dismissImageView(gestureRecognizer: UITapGestureRecognizer) { 
     // Remove the image view 
     self.imageView.removeFromSuperview() 
    } 
}