本文介绍了Swift 3 - 带有Tap Gesture的图像视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用我放在图像视图上的轻击手势时遇到了问题。图像当前存储在资产中作为'ActionLiked',我已将图像视图设置为此图像。然后将其呈现为基于JSON动态的表视图(因此,对于放入JSON数组中的每个项目,它都会重复)。我添加了敲击手势,每次点击它都打印出'TAPPED'然而,它似乎一直没有工作 - 表中有7个项目,点击手势将在1上工作然后在下2个工作然后在第四个工作并重复该模式

Im having issues with using a tap gesture that I have put on an image view. The image is currently stored in the Assets as 'ActionLiked' and I have set the image view to this image. It is then rendered into a table view which is dynamic based on JSON (so it repeats for each item I put into a JSON array). I added the tap gesture to print out 'TAPPED' each time I click on it however, it seems to not be working all the time - 7 items currently in the table, the tap gesture will work on 1 then not work on the next 2 then work on the 4th one and repeat that pattern

项目1 - 工作
项目2 - 无工作
项目3 - 无工作
第4项 - 工作
第5项 - 无工作
第6项 - 无工作
第7项 - 工作

ITEM 1 - WORKITEM 2 - NO WORKITEM 3 - NO WORKITEM 4 - WORKITEM 5 - NO WORKITEM 6 - NO WORKITEM 7 - WORK

我收到错误在我的调试控制台中
无法加载带有标识符
的捆绑中的笔尖引用的图像但是图像在每个图像上都正确显示而没有识别出点按手势?

I get an error in my debug consoleCould not load the "" image referenced from a nib in the bundle with identifierBut the image is showing correctly on each one just not recognising the tap gesture?

推荐答案

以下代码可以帮助您更好地使用swift 3

Following code may help you more with swift 3

正如您所说,您想要检测图像点击tableview单元格请仔细阅读以下代码:

As you said you want to detect image tap on tableview cell please go through this code :

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(ViewController.connected(_:)))

    cell.yourImageView.isUserInteractionEnabled = true
    cell.yourImageView.tag = indexPath.row
    cell.yourImageView.addGestureRecognizer(tapGestureRecognizer)

并将以下方法添加到您的ViewController

And add below method to your ViewController

func connected(_ sender:AnyObject){
     print("you tap image number : \(sender.view.tag)")
}

这篇关于Swift 3 - 带有Tap Gesture的图像视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 16:58