Simpo PDF Merge and Split Unregistered Version -
PART IV
Advanced iPhone
Programming Techniques
CHAPTER 14: Programming Multi-touch Applications
CHAPTER 15: Simple Animations
CHAPTER 16: Accessing Built-in Applications
CHAPTER 17: Accessing the Hardware
c14.indd 317
11/30/09 12:50:36 PM
Simpo PDF Merge and Split Unregistered Version -
c14.indd 318
11/30/09 12:50:43 PM
Simpo PDF Merge and Split Unregistered Version -
14
Programming Multi-touch
Applications
WHAT YOU WILL LEARN IN THIS CHAPTER
➤
How to detect touches in your application
➤
How to differentiate between single and double taps
➤
How to implement the pinch gesture
➤
How to implement the drag gesture
One of the most important selling points of the iPhone is its screen, which can detect multiple
points of input. Multi-touch inputs allow for very natural interaction between users and your
applications. Because of multi-touch, the mobile Safari Web browser is easily one of the most
user-friendly Web browsers available on a smart phone.
In this chapter, you learn how to detect touches in your application and then implement some
cool features that improve the interaction between the user and the application, such as a
Jigsaw Puzzle application. By detecting touches in your application, the user can rearrange
the locations of the images on the screen, as well as change the size of the images using the
pinching gesture.
DETECTING TOUCHES
Before you learn how to detect touches in your application, you fi rst need to acquaint yourself
with a few events that handle the detection of touches. You will then be able to know whether
the user has single-tapped or double-tapped on your application and react accordingly.
c14.indd 319
11/30/09 12:50:43 PM
Simpo PDF Merge and Split Unregistered Version -
320
❘
CHAPTER 14
PROGRAMMING MULTI-TOUCH APPLICATIONS
Time to get the engine rolling! Make sure you download the code indicated here so you can work
through the following Try It Out activity.
TRY IT OUT
Detecting for Taps
[MultiTouch.zip] is available for download at Wrox.com
1.
2.
Using Xcode, create a new View-based Application project and name it MultiTouch.
Drag and drop an image into the Resources folder. Figure 14-1 shows an image named
apple.jpeg located in the Resources folder.
FIGURE 14-1
3.
4.
c14.indd 320
Double-click the MultiTouchViewController.xib fi le to edit it in Interface Builder.
Populate the View window with the ImageView view. Ensure that the ImageView covers the entire
View window.
11/30/09 12:50:45 PM
Simpo PDF Merge and Split Unregistered Version -
Detecting Touches
5.
❘ 321
Select the ImageView view and view its Attributes window (see Figure 14-2). Set its Image
property to apple.jpeg.
FIGURE 14-2
6.
In the MultiTouchViewController.h fi le, add the following statements that appear in bold:
#import <UIKit/UIKit.h>
@interface MultiTouchViewController : UIViewController {
IBOutlet UIImageView *imageView;
}
@property (nonatomic, retain) UIImageView *imageView;
@end
7.
c14.indd 321
Back in Interface Builder, Control-click and drag the File’s Owner item to the ImageView view.
Select ImageView.
11/30/09 12:50:46 PM
Related Wrox Books
Beginning Mac OS X Snow Leopard Programming
Programmer to Programmer
™
Get more out of
wrox.com
Interact
Join the Community
Take an active role online by participating in our
P2P forums @ p2p.wrox.com
Sign up for our free monthly newsletter at
newsletter.wrox.com
Wrox Online Library
Browse
Hundreds of our books are available online
through Books24x7.com
Ready for more Wrox? We have books and
e-books available on .NET, SQL Server, Java,
XML, Visual Basic, C#/ C++, and much more!
Wrox Blox
Download short informational pieces and code
to keep you up to date and out of trouble!
Contact Us.
We always like to get feedback from our readers. Have a book idea?
Need community support? Let us know by e-mailing
Prepared for TOM ZASKI/ email0 Order number0 57462538 This PDF is for the purchaser’s personal use in accordance
with the Wrox Terms of Service and under US copyright as stated on this book’s copyright page. If you did not purchase this copy/ please visit
www.wrox.com to purchase your own copy.
ISBN: 9780470577523
This book serves as a solid guide to getting started with Mac OS X programming. You will learn how to use the free software development
tools that come with all Mac OS X systems and how to efficiently start writing programs on Mac OS X Snow Leopard. The author shows
you how to use all of the programming languages to use together in order to create seamless applications.
Professional Android Application Development
ISBN: 0470344717
Offering an open development environment, Android represents an exciting new opportunity to write innovative applications for mobile
devices. This book provides you with a hands-on guide to building these applications using the Android software development kit. It takes
you through a series of sample projects, each introducing new features and techniques to get the most out of Android. You’ll learn all
about the basic functionality as well as discover how to utilize the advanced features with the help of concise and useful examples. You’ll
get the grounding and knowledge that is needed to write customized mobile applications using the current Android 1.0 SDK. Plus, you’ll
also gain the flexibility to quickly adapt to future enhancements in order to build the most cutting-edge solutions.
Professional Xcode 3
ISBN: 9780470525227
The steady increase in sales of Apple computers has triggered a strong interest in gaining a thorough understanding of Xcode and its
tools and what they have to offer. This book provides you with an inside look at the array of Xcode tools from top to bottom. You’ll go
beyond the basics and dive into such in-depth topics as installing the latest version of Xcode tools, customizing the look and behavior of
Xcode, creating and managing projects, using the built-in class browser to model complex applications and structures, and more. With
this book, you’ll be able to take full advantage of the range of tools included with Xcode.
Safari and WebKit Development for iPhone OS 3.0
ISBN: 9780470549667
With the unparalleled success of iPhone and iPod touch, iPhone OS 3.0 has emerged as a compelling platform for which vast numbers of
web developers are designing and building web-based mobile applications. This book explores the Safari and WebKit development platform that
is built into iPhone OS 3.0 and takes you through the process of creating an iPhone web application from the ground up. You’ll learn how
to use existing open source frameworks to speed up your development time, imitate qualities of built-in Apple apps, cache data locally
and even run in offline mode, and more. Whether you’re eager to build new web applications for iPhone OS 3.0 or optimize existing web
sites for this platform, you have everything you need to do so within this book.
Lee
Get started developing iPhone apps
using the Apple iPhone SDK
•
•
•
•
•
Wei-Meng Lee is Founder of Developer Learning Solutions, a technology company
specializing in hands-on training of the latest Microsoft and Apple technologies.
He writes extensively for online publications and is the author of Professional
Windows Vista Gadgets Programming and C# 2008 Programmer’s Reference.
Wrox Beginning guides are crafted to make learning programming languages
and technologies easier than you think, providing a structured, tutorial format
that will guide you through all the techniques involved.
Programming / Mac & iPhone
$39.99 USA
$47.99 CAN
Programmer
Forums
Join our Programmer to
Programmer forums to ask
and answer programming
questions about this book,
join discussions on the
hottest topics in the industry,
and connect with fellow
programmers from around
the world.
Code Downloads
Take advantage of free code
samples from this book, as
well as code samples from
hundreds of other books, all
ready to use.
Read More
Find articles, ebooks, sample
chapters and tables of contents
for hundreds of books, and
more reference resources on
programming topics that matter
to you.
đ
ã
ã
Explains how the fundamental concepts of outlets and actions allow
your code to interact with the visual elements in Interface Builder
Describes the use of the various views that make up the user
interface (UI) of your iPhone apps
Shows you how to build Tab Bar, Navigation, and Utility applications
Explores the powerful Table view and how it can be used to display
rows of data
Discusses using application settings to persist application preferences
Demonstrates how to implement multi-touch capability in your
iPhone application
Introduces the various techniques you can apply to develop animations
for the iPhone
wrox.com
iPhone SDK
Beginning iPhone SDK:
Wrox Programmer to Programmer™
Beginning
Programming with Objective-C®
Learning to develop iPhone applications doesn’t need to be an
overwhelming undertaking. This book provides an easy-to-follow,
example-driven introduction to the fundamentals of the Apple
iPhone SDK and offers you a clear understanding of how
things are done when programming iPhone applications with
Objective-C. As you progress through the exercises featured in
each chapter, you will discover the simple logic behind each step
required for creating your own iPhone applications. When you
reach the end of the book, you will be prepared to confidently
tackle your next iPhone programming challenge.
Join the discussion @ p2p.wrox.com
Beginning
iPhone SDK
®
®
Programming with Objective-C
Wei-Meng Lee