in XCode 12, using Swift 5, create a new Project using the Game SpriteKit technology. That generates amongst other things:
- GameViewController.swift
- GameScene.swift
In GameScene.swift I added
after the class definition
let tapRec2 = UITapGestureRecognizer()in override func didMove(to view: SKView) {
tapRec2.addTarget(self, action:#selector(GameScene.tappedView2(_:) )) tapRec2.numberOfTouchesRequired = 1 tapRec2.numberOfTapsRequired = 2 //2 taps i self.view!.addGestureRecognizer(tapRec2)the implementation of tappedView2 function to detect a double tap.
@objc func tappedView2(_ sender:UITapGestureRecognizer) { let controller = self.view?.window?.rootViewController let new_controller = ViewController() print("double click detected") controller?.navigationController?.pushViewController(new_controller, animated: true) }
- I then created a ViewController class using the template https://gist.github.com/phynet/075d538c93c0bfe62596bc4d47a482e1
I compiled it and run it, the app starts appropriately and if I do a double click it detects it, however no ViewController is displayed. What am I doing wrong ?
found the solution by simplifying tappedView2 to the following code:
and simplified the UIViewController to: