Swift - How to remove swipe gesture from scene when moving to another one?

前端 未结 3 1015
死守一世寂寞
死守一世寂寞 2021-01-03 14:32

So my game uses swipe gestures, in my didMoveToView() function I have these gestures initialized:

            let swipeRight = UISwipeGestureRecognizer()
            


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-03 15:08

    The following removes all swipe gesture recognizers from the view:

    override func willMoveFromView(view: SKView) {
        if let gestures = view.gestureRecognizers {
            for gesture in gestures {
               if let recognizer = gesture as? UISwipeGestureRecognizer {
                    view.removeGestureRecognizer(recognizer)
               }
            }
        }
    }
    

提交回复
热议问题