How do I implement the UITapGestureRecognizer into my application

前端 未结 5 1991
梦如初夏
梦如初夏 2020-11-27 06:20

I am quite new to programming and Objective C. I was wondering how to make an app which has a blank screen and a timer that goes for one minute. You are meant to tap as fast

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 07:02

    If you are working Swift (iOS9) and SpriteKit, try the following.

    class GameScene: SKScene {
        override func didMoveToView(view: SKView) {
            let singleTap = UITapGestureRecognizer(target:self, action:#selector(self.handleSingleTap:))
            singleTap.numberOfTouchesRequired = 1
            singleTap.addTarget(self, action:#selector(self.handleSingleTap))
            view.userInteractionEnabled = true
            view.addGestureRecognizer(singleTap)
        }
        //event handler
        func handleSingleTap(sender:UITapGestureRecognizer){
            print("tapped")
        }
    }
    

提交回复
热议问题