如何通过轻击手势传递UIImage

时间:2017-03-03 05:21:13

标签: ios swift uitapgesturerecognizer

问题os在无效的手势中传递图像,我想用轻拍手势传递图像,并且该图像用于其他目的..

func addGestureToImageView(imgView:UIImageView) {
let tapGesture1 = UITapGestureRecognizer(target: self, action:#selector(self.tapImage(tap: ,img:imageview)))
    imgView.addGestureRecognizer(tapGesture1)
}

该功能调用轻击手势..

func tapImage(tap:UITapGestureRecognizer,img:UIImage) {
   viewDisplay(img:img)
}

我想使用那个图像..请提供解决方案。

2 个答案:

答案 0 :(得分:2)

您可以直接从imageview获取图片

  func tapImage(_tap:UITapGestureRecognizer) {

   if let getImage = tap.view as! UIImageView
    {
          viewDisplay(getImage:img)
      }

}

表示样本

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self. tapImage(_:)))
imgView.isUserInteractionEnabled = true
imgView.addGestureRecognizer(tapGesture)

并将操作处理为

func tapImage(_ tap: UITapGestureRecognizer) {

   if let getImage = tap.view as! UIImageView
    {
          viewDisplay(getImage:img)
      }

}

答案 1 :(得分:1)

PHP