Chapter 11. Handling Touch Events
In This Chapter
Handling touch events in your custom UIViews |
Implementing the methods needed to handle touch events |
Learning about the UITouch class and how to use it |
Configuring a UIView to receive multi-touch events |
Extending the custom UIView sample code to handle touches and multi-touches |
A defining feature of the iPhone is its use of multi-touch for its primary input. There is nothing more unique to iPhone than this capability. When working with custom views, it's important to utilize multi-touch to its greatest advantage. Fortunately, Cocoa Touch makes implementing a multi-touch interface on your custom views incredibly easy. All you have to do is override a few methods to handle the touch events to unlock the potential of this innovative capability.
In this chapter, you're going to take a look at how you implement multi-touch on a custom view. First, you will take a look at what you need to do to support multi-touch, and then you will implement multi-touch on your custom UIView
example code from the last chapter.
Handling Touch Events in a Custom UIView
When the user's finger touches the iPhone screen, the view that the touch occurs within receives a set of messages. These messages are translated into calls to specific methods that are defined as part of the UIResponder
class. UIView
, as a subclass of UIResponder
, also has the option to override these methods so that it can take action on these events. The methods that are called are touchesBegan:withEvent:, ...
Get Cocoa Touch™ for iPhone® OS 3 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.