Swift 3 TapGestureRecognizer 选择器抛出错误
Posted
技术标签:
【中文标题】Swift 3 TapGestureRecognizer 选择器抛出错误【英文标题】:Swift 3 TapGestureRecognizer selector throwing error 【发布时间】:2017-09-18 13:28:07 【问题描述】:我查看了其他几篇关于添加目标的问题,而不仅仅是点击手势和按钮,我认为我正确地遵循了格式,但仍然收到“没有成员”错误,这是我的伪代码:
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.handlTap(_:)))
func handleTap(_ sender: AnyObject)
【问题讨论】:
【参考方案1】:将手势添加到您的视图中:
view.addGestureRecognizer(yourGesture)
【讨论】:
【参考方案2】:使用 UITapGestureRecognizer 访问任何对象
let recognizer = UITapGestureRecognizer(target: self, action: #selector(self.expand))
view.addGestureRecognizer(recognizer)
func expand(sender:UITapGestureRecognizer)
if let myImg = sender.view as? UIImageView //or AnyObject you want
【讨论】:
以上是关于Swift 3 TapGestureRecognizer 选择器抛出错误的主要内容,如果未能解决你的问题,请参考以下文章
swift takasek / CodePiece.swiftのSwift 3.1版