Swift:关闭图像视图

时间:2014-11-02 16:14:38

标签: ios input swift uiimageview dismiss

我的视图控制器中有一个UIImageView(通过故事板设置),我只是想知道如何在触摸时解除它(这是一个开始'点击的图像)。

提前致谢,

威廉

1 个答案:

答案 0 :(得分: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()
    }
}