Reputation: 1
first off, i am new to swift development. i am learning and things are going mostly smoothly but i've come across this issue and can't seem to beat it down. i searched but there just isn't a lot of info out there. the few questions relating to this issue on SO aren't helpful either (perhaps i just don't know the proper terms to search for..?)
anyway.
i have set up my gesture recognizers for swipes, taps and long presses. they work fine. the problem comes when i do the long press. the long press is used to trigger player movement (technically it moves the background image(s)) it works, he animates and moves but while moving the system does not recognize any other gesture input. the moment i let go of the long press the other recognizers function as they should.
in my GameViewController i added
skView.multipleTouchEnabled = true
but it had no affect. it still doesn't seem to register the additional touch events while the long press is active. my code is below.
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
// gesture recognizer
// swipe up
let swipeUp:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(GameScene.handleSwipe(_:)))
swipeUp.direction = .Up
view.addGestureRecognizer(swipeUp)
// swipe dn
let swipeDn:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(GameScene.handleSwipe(_:)))
swipeDn.direction = .Down
view.addGestureRecognizer(swipeDn)
// swipe rt
let swipeRt:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(GameScene.handleSwipe(_:)))
swipeRt.direction = .Right
view.addGestureRecognizer(swipeRt)
// swipe lt
let swipeLt:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(GameScene.handleSwipe(_:)))
swipeLt.direction = .Left
view.addGestureRecognizer(swipeLt)
// tap
let tapped:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(GameScene.handleTap(_:)))
view.addGestureRecognizer(tapped)
// long press
let pressed:UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(GameScene.handlePress(_:)))
pressed.minimumPressDuration = 0.1
view.addGestureRecognizer(pressed)
}
// swipes
func handleSwipe(sender: UISwipeGestureRecognizer) {
switch sender.direction {
case UISwipeGestureRecognizerDirection.Right:
swipeRT = true
print("swipe RIGHT")
case UISwipeGestureRecognizerDirection.Left:
swipeLT = true
print("swipe LEFT")
case UISwipeGestureRecognizerDirection.Up:
swipeUP = true
print("swipe UP")
case UISwipeGestureRecognizerDirection.Down:
swipeDN = true
print("swipe DOWN")
default:
print("nothing to see here")
}
}
// taps
func handleTap(sender: UITapGestureRecognizer) {
print("tap")
}
func handlePress(sender: UILongPressGestureRecognizer) {
if sender.state == .Began {
theWAY()
}
if sender.state == .Ended {
player.runAction(animIdle)
moving = false
}
}
i realize that there may be better/more efficient ways of achieving this. i'm 100% open to suggestions and critique. as i said, i'm new to this whole thing. thanks for any help and i apologize if this runs afoul of the whole "search before you post" thing. i did search, i promise.
Upvotes: 1
Views: 391
Reputation: 7031
You can use the UIGestureRecognizerDelegate
method gestureRecognizer(_:shouldRecognizeSimultaneouslyWithGestureRecognizer:)
.
See this question and answer for reference.
Upvotes: 1