Changes

Jump to: navigation, search

An iOS 8 Swift Gesture Recognition Tutorial

41 bytes added, 04:32, 10 November 2016
Designing the User Interface
<table border="0" cellspacing="0" width="100%">
<tr>
<td width="20%">[[Identifying Gestures using iOS 8 Gesture Recognizers|Previous]]<td align="center">[[iOS 8 App Development Essentials|Table of Contents]]<td width="20%" align="right">[[Implementing TouchID Authentication in An iOS 8 Apps9 3D Touch Force Handling Tutorial|Next]]</td>
<tr>
<td width="20%">Identifying Gestures using iOS 8 10 Gesture Recognizers<td align="center"><td width="20%" align="right">Implementing TouchID Authentication in An iOS 8 Apps10 3D Touch Force Handling Tutorial</td>
</table>
<hr>
Select the label object in the view canvas, display the Assistant Editor panel and verify that the editor is displaying the contents of the ViewController.swift file. Ctrl-click on the same label object and drag to a position just below the class declaration line in the Assistant Editor. Release the line and, in the resulting connection dialog, establish an outlet connection named statusLabel.
<htmlet>ios10</htmlet>
<htmlet>adsdaqbox_flow</htmlet>
Next, the non-visual gesture recognizer objects need to be added to the design. Scroll down the list of objects in the Object Library panel until the Tap Gesture Recognizer object comes into view. Drag and drop the object onto the View in the design area (if the object is dropped outside the view, the connection between the recognizer and the view on which the gestures are going to be performed will not be established). Repeat these steps to add Pinch, Rotation, Swipe and Long Press Gesture Recognizer objects to the design. Note that the document outline panel (which can be displayed by clicking on the panel button in the lower left-hand corner of the storyboard panel) has updated to reflect the presence of the gesture recognizer objects as illustrated in Figure 56-1. An icon for each recognizer added to the view also appears within the toolbar across the top of the storyboard scene.
[[Image:xcode_6_gestures_in_outline.png|Gesture recognizers listed in the Xcode document outline panel]]
Figure 56-1
Having added and configured the gesture recognizers, the next step is to connect each recognizer to its corresponding action method.
Display the Assistant Editor and verify that it is displaying the content of ViewController.swift. Ctrl-click on the Tap Gesture Recognizer object either in the document outline panel or in the scene toolbar and drag the line to the area immediately beneath the viewDidLoad method in the Assistant Editor panel. Release the line and, within the resulting connection dialog, establish an Action method configured to call a method named tapDetected with the Type value set to UITapGestureRecognizer as illustrated in Figure 56-2:  [[Image:]] Figure 56-2.
<htmlet>ios10</htmlet>
<table border="0" cellspacing="0" width="100%">
<tr>
<td width="20%">[[Identifying Gestures using iOS 8 Gesture Recognizers|Previous]]<td align="center">[[iOS 8 App Development Essentials|Table of Contents]]<td width="20%" align="right">[[Implementing TouchID Authentication in An iOS 8 Apps9 3D Touch Force Handling Tutorial|Next]]</td>
<tr>
<td width="20%">Identifying Gestures using iOS 8 10 Gesture Recognizers<td align="center"><td width="20%" align="right">Implementing TouchID Authentication in An iOS 8 Apps10 3D Touch Force Handling Tutorial</td>
</table>

Navigation menu