Xcode Swift&x2013;什么';此UILongPressGestureRecognitor代码有什么问题?

Xcode Swift&x2013;什么';此UILongPressGestureRecognitor代码有什么问题?,xcode,swift,Xcode,Swift,当两边都长按时,我试图将节点向左和向右移动。因此,如果在左侧长按,节点将向左移动,在右侧长按,节点将向右移动。我将此代码放在didMoveToView中,但它对我不起作用。我做错了什么 func beginTouchRecognizer(){ let longPress = UILongPressGestureRecognizer(target: self, action: Selector("longPressTouch:")) longPress.minimumPressDu

当两边都长按时,我试图将节点向左和向右移动。因此,如果在左侧长按,节点将向左移动,在右侧长按,节点将向右移动。我将此代码放在
didMoveToView
中,但它对我不起作用。我做错了什么

func beginTouchRecognizer(){
    let longPress = UILongPressGestureRecognizer(target: self, action: Selector("longPressTouch:"))
    longPress.minimumPressDuration = 1.0
    longPress.numberOfTapsRequired = 0
    longPress.numberOfTouchesRequired = 1

   self.view?.addGestureRecognizer(longPress)
}

let WidthOfTapArea: CGFloat = 100

func longPressTouch(recognizer: UILongPressGestureRecognizer) {
    let location = recognizer.locationInView(self.view)
    if location.x < CGRectGetMidX(self.frame) {
        hero.position.x -= WidthOfTapArea
    } else {
        hero.position.x += WidthOfTapArea
    }
}
func begintouch识别器(){
让longPress=UILongPress手势识别器(目标:自我,动作:选择器(“longPressTouch:”)
longPress.minimumPressDuration=1.0
longPress.numberOfTapsRequired=0
longPress.numberOfTouchesRequired=1
self.view?.addgestureignizer(longPress)
}
让面积宽度:CGFloat=100
func longPressTouch(识别器:UILongPressGestureRecognitor){
let location=recognizer.locationInView(self.view)
如果location.x
是否检查BeginTouch识别器是否被调用?如果它被调用,是手势识别器添加到的视图,而不是零?是否在视图上启用了触摸?如果是这样,选择器会被调用吗?我不知道我做错了什么。我添加了longPress.enabled=true,但它仍然不起作用。在过去的三天里,我一直在努力让它发挥作用。