我正试图在两侧长按时向左和向右移动节点。因此,如果左侧有长按,节点向左移动,长按在右侧,节点向右移动。我将此代码放在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
}
}