UIView中UIImageView的手势识别器

时间:2016-12-22 10:14:22

标签: ios swift delegates uigesturerecognizer

我在superview中添加了UIImageView然后添加了必需的手势并且工作正常但是在另一个UIView中执行相同操作时(在UIImageView中添加UIView并添加手势)不行,我认为这是关于代表的,但我无法弄清楚。

请使用Swift中的代码。

view hierarchy

1 个答案:

答案 0 :(得分:5)

添加UIGestureRecognizerDelegate

实施例 -

self.imgView.isUserInteractionEnabled = true
self.view.isUserInteractionEnabled = true
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(imageTapped))
imgView.addGestureRecognizer(tapRecognizer)

在UIView或ImageView上添加你想要的手势

func imageTapped(gestureRecognizer: UITapGestureRecognizer)
{
    let tappedImageView = gestureRecognizer.view!
    let imageView = tappedImageView as! UIImageView
 }