我的视图控制器中有一个UIImageView(通过故事板设置),我只是想知道如何在触摸时解除它(这是一个开始'点击的图像)。
提前致谢,
威廉
答案 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()
}
}