Changes

Jump to: navigation, search

An Overview of iOS 4 iPhone Multitouch, Taps and Gestures

1,911 bytes removed, 19:55, 27 October 2016
m
Text replacement - "<table border="0" cellspacing="0">" to "<table border="0" cellspacing="0" width="100%">"
<table border="0" cellspacing="0" width="100%">
<tr>
<td width="20%">[[An iOS 4 iPhone Core Data Tutorial|Previous]]<td align="center">[[iPhone iOS 4 Development Essentials|Table of Contents]]<td width="20%" align="right">[[An Example iOS 4 iPhone Touch, Multitouch and Tap Application|Next]]</td>
<tr>
<td width="20%">An iOS 4 iPhone Core Data Tutorial<td align="center"><td width="20%" align="right">An Example iOS 4 iPhone Touch, Multitouch and Tap Application</td>
</table>
<hr>
 
 
<htmlet>ios9_upgrade</htmlet>
 
 
In terms of physical points of interaction between the device and the user, the iPhone provides three buttons, a switch and a touch screen. Without question, the user will spend far more time using the touch screen than any other aspect of the device. It is essential, therefore, that any application be able to handle gestures (touches, multitouches, taps, swipes and pinches etc) performed by the user’s fingers on the touch screen.
== The Responder Chain ==
<google>IOSBOX</google>
In the chapter entitled [[Understanding iPhone iOS 4 Views, Windows and the View Hierarchy]] we spent some time talking about the view hierarchy of an application’s user interface and how that hierarchy also defined part of the application’s responder chain. In order to fully understand the concepts behind the handling of touch screen gestures it is first necessary to spend a little more time learning about the responder chain.
== Touch Notification Methods ==
<htmlet>adsdaqbox_flow</htmlet>Touch screen events cause one of four methods on the first responder object to be called. The method that gets called for a specific event will depend on the nature of the interaction. In order to handle events, therefore, it is important to ensure that the appropriate methods from those outlined below are implemented within your responder chain. These methods will be used in the worked example contained in the [[An Example iOS 4 Phone MultitouchiPhone Touch, Tap Multitouch and Gesture Event Handling TutorialTap Application]] and [[Detecting iOS 4 iPhone Touch Screen Gesture Motions]] chapters of this book:
=== touchesBegan method ===
=== touchesCancelled method ===
When a gesture is interrupted due to a high level interrupt, such as the phone detecting an incoming call, the touchesCancelled method is called.
== Summary ==
In order to fully appreciate the mechanisms for handling touch screen events within an iOS 4 iPhone application, it is first important to understand both the responder chain and the methods that are called on a responder depending on the type of interaction. We have covered these basics in this chapter. In the next chapter, entitled [[An Example iOS 4 Phone MultitouchiPhone Touch, Tap Multitouch and Gesture Event Handling Tutorial Tap Application]] we will use these concepts to create an example application that demonstrates touch screen event handling. 
<htmlet>ios9_upgrade</htmlet>
== Taps ==
A tap, as the name suggests, occurs when the user touches the screen with a single finger and then immediately lifts it from the screen. Taps can be single-taps or multiple-taps and the event will contain information about the number of times a user tapped on the screen.
 
== Touches ==
 
A touch occurs when a finger establishes contact with the screen. When more than one finger touches the screen each figure registers as a touch up to a maximum of five fingers.
 
== Touch Notification Methods ==
 
Touch screen events cause one of four methods on the first responder object to be called. The method that gets called for a specific event will depend on the nature of the interaction. In order to handle events, therefore, it is important to ensure that the appropriate methods from those outlined below are implemented within your responder chain. These methods will be used in the worked example contained in the [[iOS 4 Phone Multitouch, Tap and Gesture Event Handling Tutorial]] and [[Detecting iOS 4 iPhone Touch Screen Gesture Motions]] chapters of this book:
 
=== touchesBegan method ===
 
The touchesBegan method is called when the user first touches the screen. Passed to this method are an argument called touches of type NSSet and the corresponding UIEvent object. The touches object contains a UITouch event for each finger in contact with the screen. The tapCount method of any of the UITouch events within the touches set can be called to identify the number of taps, if any, performed by the user. Similarly, the coordinates of an individual touch can be identified from the UITouch event either relative to the entire screen or within the local view itself.
 
=== touchesMoved method ===
 
The touchesMoved method is called when one or more fingers move across the screen. As fingers move across the screen this method gets called multiple times allowing the application to track the new coordinates and touch count at regular intervals. As with the touchesBegan method, this method is provided with an event object and an NSSet object containing UITouch events for each finger on the screen.
 
=== touchesEnded method ===
 
This method is called when the user lifts one or more fingers from the screen. As with the previous methods, touchesEnded is provided with the event and NSSet objects.
 
=== touchesCancelled method ===
 
When a gesture is interrupted due to a high level interrupt, such as the phone detecting an incoming call, the touchesCancelled method is called.
 
== Summary ==
In order to fully appreciate the mechanisms for handling touch screen events within an <htmlet>ezoicbottom</htmlet><hr><table border="0" cellspacing="0" width="100%"><tr><td width="20%">[[An iOS 4 iPhone application, it is first important to understand both the responder chain and the methods that are called on a responder depending on the type Core Data Tutorial|Previous]]<td align="center">[[iPhone iOS 4 Development Essentials|Table of interaction. We have covered these basics in this chapter. In the next chapter, entitled Contents]]<td width="20%" align="right">[[An Example iOS 4 Phone MultitouchiPhone Touch, Tap Multitouch and Gesture Event Handling Tap Application|Next]]</td><tr><td width="20%">An iOS 4 iPhone Core Data Tutorial we will use these concepts to create an example application that demonstrates touch screen event handling. <td align="center"><td width="20%" align="right">An Example iOS 4 iPhone Touch, Multitouch and Tap Application</td></table>

Navigation menu