UITapGestureRecogniser问题

时间:2016-09-14 10:47:37

标签: uitapgesturerecognizer

UITapGestureRecogniser仅在图像视图中存在图像时才有效。就我而言,TapGesture甚至可以在图像视图中显示图像。

我的代码是:

func tapGestureRecogniser() {
        if let _ = displayImageView.image {
            let tapGestureRecogniser = UITapGestureRecognizer(target: self, action: #selector(AddDiaryTableViewController.displayImageViewTapped(_:)))
            displayImageView.userInteractionEnabled = true
            displayImageView.addGestureRecognizer(tapGestureRecogniser)
        }
    }

    func displayImageViewTapped(sender: AnyObject) {
        print("hello")
    }

在viewDidLoad()

中调用tapGestureRecogniser()

1 个答案:

答案 0 :(得分:1)

实施tapGestureRecogniser的委托并在此处返回,直到您在图片视图中正确加载图片。