O'Reilly logo

Learning Swift™ Programming by Jacob Schatz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding the Controls

You can now add some rudimentary controls so that the hero is able to move around when a player touches the screen. You could do this by using the accelerometer, and you could also do it by using screen tapping or swiping. In this case, you will use screen tapping for now. Add the following code to the bottom of your viewDidLoad method, and note that it includes some commented code for handling swipes in two different directions:

let gestureRecognizers = NSMutableArray()let tapGesture = UITapGestureRecognizer(target: self, action: "handleTap:")tapGesture.numberOfTouchesRequired = 1let twoTapGesture = UITapGestureRecognizer(target: self, action: "handleTwoTap:")twoTapGesture.numberOfTouchesRequired ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required