我有一个名为 CommentsTableViewCell
的 UITableViewCell
类,其中包括一个 UIImageView
和一个 UILabel
。
我正在使用的代码:
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(CommentsTableViewCell.showUserViewController))
nameLabel.userInteractionEnabled = true
avatarRoundImageView.userInteractionEnabled = true
nameLabel.addGestureRecognizer(tapGesture)
avatarRoundImageView.addGestureRecognizer(tapGesture)
如您所知,我有一个函数,每当点击 UIImageView
或 UILabel
时,它都会显示另一个 UIViewController
。
令我困惑的是 tapGesture
在 UIImageView
上正常工作,但在 UILabel
上却不正常。
有什么想法吗?
最佳答案
你需要不同的手势来控制
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(CommentsTableViewCell.showUserViewController))
avatarRoundImageView.userInteractionEnabled = true
avatarRoundImageView.addGestureRecognizer(tapGesture)
let tapGesture2 = UITapGestureRecognizer(target: self, action: #selector(CommentsTableViewCell.showUserViewController))
nameLabel.userInteractionEnabled = true
nameLabel.addGestureRecognizer(tapGesture2)
关于ios - UITapGestureRecognizer 在 UIImageView 上工作,但不在 UILabel 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40483099/