首页 文章

UIView中UIImageView的手势识别器

提问于
浏览 1244
2

我在superview中添加 UIImageView 然后添加所需的手势并且工作正常但是当在另一个 UIView (在 UIView 中添加 UIImageView 并添加手势)中执行相同时它不起作用我认为's about delegates but I can' t弄明白了 .

请在Swift代码中 .

view hierarchy

1 回答

  • 5

    添加UIGestureRecognizerDelegate

    EX-

    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
     }
    

相关问题