删除发件人后,我可以调用“handleTap”函数,但只要我重新添加sender: UIPanGestureRecognizer
,就会收到此错误:unrecognized selector sent to instance
。我无法理解!
class DrawingViewController: UIViewController, UIGestureRecognizerDelegate {
var newlyAddedSticker = UIImage() {
didSet {
makeNewSticker()
}
}
func makeNewSticker() {
let newSticker = UIImageView(image: newlyAddedSticker)
view.addSubview(newSticker)
let myPanGesture = UIPanGestureRecognizer(target: self, action: "handleTap:")
myPanGesture.delegate = self
newSticker.isUserInteractionEnabled = true
newSticker.addGestureRecognizer(myPanGesture)
}
func handleTap(sender: UIPanGestureRecognizer) {
print("hi")
}
}
答案 0 :(得分:1)
问题是你没有指定选择器
let myPanGesture = UIPanGestureRecognizer(target: self, action: #selector(YourViewController.handleTap))
func handleTap() {
print("hi")
}
希望这会有所帮助