Table Of ContentCYAN YELLOW SPOT MATTE
MAGENTA BLACK
PANTONE 123 C
BOOKS FOR PROFESSIONALS BY PROFESSIONALS® Companion
eBook
Available
Building Apps That
I B
t’s in magazines and newspapers, it’s on television and radio, it’s on bus-
e
ses and billboards and pretty much everywhere you look (except for Apple g Make the iPad Shine
stores, where it’s likely still sold out). The iPad is the hot new touchscreen tab- in
let from Apple, representing the next generation of mobile computing. n
i
n
Packed with dozens of new features, the iPad SDK enables you to build sophis- g
ticated, desktop-quality apps for this exciting new platform. Every iPhone and
i
iPod touch app developer looking to take the next step and move into the P
iPad arena will want to read this book from cover to cover.
a
Beginning iPad Development for iPhone Developers: Mastering the iPad SDK has d
all the answers, and you’ll find them presented with the same easy-to-follow
style and thorough coverage you’ve come to expect from titles like Beginning D
iPhone 3 Development—everything an aspiring iPad developer needs to know e
to create great apps.
v
Best-selling authors Jack Nutting, Dave Wooldridge, and Dave Mark show e
iPhone developers how to master all of the iPad-exclusive frameworks and l
features, which are explained, demonstrated in action, and put through their o
paces in this comprehensive programming guide. You’ll get a detailed un- p
derstanding of the new feature set and gain every possible advantage in the
m
iTunes App Store.
What you’ll learn: e
• How to design app interfaces optimized for the iPad by taking n Beginning
advantage of new UIKit features such as Popovers, Split View
t
Controllers, and new Modal Views.
• f
How to utilize new graphics functionality, Core Text, Document o
iPad Development
Sharing, and advanced input methods to build powerful productivity r
solutions. i
P
•
How to embrace the iPad’s superior media capabilities with its new
video and display options. h
• How to convert an existing iPhone project into a stand-alone iPad o
app or a Universal app for both iPhone and iPad users. n
This book is for all iPhone app developers who want to leverage their skills to e iPhone Developers
for
create professional apps for the iPad. It includes extensive example projects and
D
the complete source code for Dudel, a full-fledged drawing app for the iPad.
e
v
Mastering the iPad SDK
W
o
N
o
lu
COMPANION eBOOK SEE LAST PAGE FOR DETAILS ON $10 eBOOK VERSION ISBN 978-1-4302-3021-2 Marridgttin Jack Nutting | Dave Wooldridge | David Mark
keg
53999
US $39.99
Shelve in:
Mobile Computing
SOURCE CODE ONLINE
User level:
www.apress.com Intermediate–Advanced 9 781430 230212
this print for content only—size & color not accurate Trim: 7.5 x 9.25 spine = 0.75" 272 page count
Beginning iPad
Development for iPhone
Developers
Mastering the iPad SDK
■ ■ ■
Jack Nutting
Dave Woolridge
David Mark
i
Beginning iPad Development for iPhone Developers: Mastering the iPad SDK
Copyright © 2010 by Jack Nutting, Dave Wooldridge, David Mark
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and the
publisher.
ISBN-13 (pbk): 978-1-4302-3021-2
ISBN-13 (electronic): 978-1-4302-3022-9
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
President and Publisher: Paul Manning
Lead Editor: Clay Andres
Development Editor: Douglas Pundick
Technical Reviewer: Mark Dalrymple
Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell,
Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan
Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic
Shakeshaft, Matt Wade, Tom Welsh
Coordinating Editor: Kelly Moritz
Copy Editor: Marilyn Smith
Compositor: MacPS, LLC
Indexer: Kevin Broccoli
Artist: April Milne
Cover Designer: Anna Ishchenko
Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring
Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
[email protected], or visit www.springeronline.com.
For information on translations, please e-mail [email protected], or visit www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or
promotional use. eBook versions and licenses are also available for most titles. For more
information, reference our Special Bulk Sales–eBook Licensing web page at
www.apress.com/info/bulksales.
The information in this book is distributed on an “as is” basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in this work.
The source code for this book is available to readers at www.apress.com. You will need to answer
questions pertaining to this book in order to successfully download the code.
ii
To Weronica, for believing in me
—Jack Nutting
To my wonderful wife and soul mate, Madeline, for her amazing love and support
—Dave Wooldridge
To my best friend and partner in life, Deneen
LFU4FREIH
—David Mark
iii
Contents at a Glance
■Contents at a Glance.......................................................................................iv
■Contents..........................................................................................................v
■About the Authors ..........................................................................................ix
■About the Technical Reviewer.........................................................................x
■Acknowledgments..........................................................................................xi
■Preface..........................................................................................................xii(cid:1)
■Chapter 1: Welcome to the Paradigm Shift.....................................................1(cid:1)
■Chapter 2: Getting Started with iPad Development.......................................19(cid:1)
■Chapter 3: Exploring the iPhone SDK’s New iPad Features...........................39(cid:1)
■Chapter 4: New Graphics Functionality.........................................................67(cid:1)
■Chapter 5: Using Core Text............................................................................99(cid:1)
■Chapter 6: Popovers....................................................................................119(cid:1)
■Chapter 7: Video and Display Output...........................................................151(cid:1)
■Chapter 8: Split Views and Modal Modes....................................................163(cid:1)
■Chapter 9: New Input Methods....................................................................191(cid:1)
■Chapter 10: Working with Documents.........................................................209(cid:1)
■Chapter 11: From iPhone to iPad.................................................................221(cid:1)
■Chapter 12: Additional Resources for iPad Development............................239(cid:1)
■Index............................................................................................................247
iv
Contents
■Contents at a Glance.......................................................................................iv(cid:1)
■Contents..........................................................................................................v(cid:1)
■About the Authors ..........................................................................................ix(cid:1)
■About the Technical Reviewer.........................................................................x(cid:1)
■Acknowledgments..........................................................................................xi
■Preface..........................................................................................................xii(cid:1)
■Chapter 1: Quick Welcome to the Paradigm Shift...........................................1(cid:1)
Reinventing the Tablet............................................................................................................................................1(cid:1)
It’s All About the Software.................................................................................................................................2(cid:1)
The iPad Is Not a Big iPod touch........................................................................................................................3(cid:1)
Personal Computing for the Masses.......................................................................................................................5(cid:1)
Developing Apps for the iPad..................................................................................................................................7(cid:1)
When Your iPhone App Is No Longer Good Enough...........................................................................................7(cid:1)
Exploring the Possibilities..................................................................................................................................8(cid:1)
Opportunity Awaits...............................................................................................................................................16(cid:1)
■Chapter 2: Getting Started with iPad Development.......................................19(cid:1)
Acquiring the Tools of the Trade...........................................................................................................................19(cid:1)
Enrolling in the iPhone Developer Program.....................................................................................................19(cid:1)
Installing iPhone SDK 3.2.................................................................................................................................20(cid:1)
Working with Beta Versions of the SDK...........................................................................................................21(cid:1)
New to Objective-C and Cocoa Touch?.................................................................................................................23(cid:1)
Embracing the Model-View-Controller Concept....................................................................................................24(cid:1)
Reusability in Xcode.........................................................................................................................................25(cid:1)
Designing in Interface Builder.........................................................................................................................28(cid:1)
The Importance of Delegates................................................................................................................................33(cid:1)
Improving App Usability with UIKit........................................................................................................................35(cid:1)
Primed for Programming......................................................................................................................................37(cid:1)
(cid:1)
v
■ CONTENTS
■Chapter 3: Exploring the iPhone SDK’s New iPad Features...........................39(cid:1)
Optimizing Apps for the iPad................................................................................................................................39(cid:1)
Examining the Tablet.......................................................................................................................................39(cid:1)
Managing Memory...........................................................................................................................................40(cid:1)
Testing Your Apps on an iPad..........................................................................................................................41(cid:1)
What’s New in iPhone SDK 3.2 for the iPad..........................................................................................................42(cid:1)
Shape Drawing................................................................................................................................................42(cid:1)
PDF Files..........................................................................................................................................................44(cid:1)
Core Text..........................................................................................................................................................45(cid:1)
Popovers..........................................................................................................................................................46(cid:1)
Video Playback and Display Options................................................................................................................49(cid:1)
Split View Controller........................................................................................................................................51(cid:1)
Modal Presentation Styles...............................................................................................................................54(cid:1)
Advanced Input Methods.................................................................................................................................56(cid:1)
Document Support...........................................................................................................................................59(cid:1)
Universal Applications.....................................................................................................................................61(cid:1)
Required Project Images for iPad Apps................................................................................................................64(cid:1)
App Icon Images..............................................................................................................................................64(cid:1)
Document Type Icon Images............................................................................................................................65(cid:1)
Default Launch Images....................................................................................................................................65(cid:1)
Drilling Deeper......................................................................................................................................................66(cid:1)
■Chapter 4: New Graphics Functionality.........................................................67(cid:1)
Bezier Paths..........................................................................................................................................................67(cid:1)
Introducing Dudel..................................................................................................................................................68(cid:1)
Creating the Dudel Project...............................................................................................................................69(cid:1)
Adding a Simple GUI........................................................................................................................................73(cid:1)
The Basic Drawing Architecture...........................................................................................................................74(cid:1)
We Are All Tool Users............................................................................................................................................76(cid:1)
The Pencil Tool.................................................................................................................................................79(cid:1)
The Line Tool....................................................................................................................................................85(cid:1)
The Ellipse and Rectangle Tools......................................................................................................................88(cid:1)
The Freehand Tool...........................................................................................................................................93(cid:1)
PDF Generation.....................................................................................................................................................96(cid:1)
Things to See and Do............................................................................................................................................98(cid:1)
■Chapter 5: Using Core Text............................................................................99(cid:1)
Why Core Text?.....................................................................................................................................................99(cid:1)
The Structure of Core Text..................................................................................................................................100(cid:1)
Preparing Dudel for a New Tool..........................................................................................................................103(cid:1)
Preparing the Controller Interface.................................................................................................................103(cid:1)
Setting Up the GUI..........................................................................................................................................104(cid:1)
Implementing Changes to the Controller Class..............................................................................................105(cid:1)
Creating the Text Tool....................................................................................................................................106(cid:1)
Creating a New Drawable Class.....................................................................................................................112(cid:1)
Rendering Multiple Styles..............................................................................................................................114(cid:1)
The Lessons of Core Text....................................................................................................................................117(cid:1)
■Chapter 6: Popovers....................................................................................119(cid:1)
Popover Preparations..........................................................................................................................................119(cid:1)
vi
■ CONTENTS
The Basic GUI.................................................................................................................................................120(cid:1)
Popover Considerations.................................................................................................................................122(cid:1)
The Font Name Popover......................................................................................................................................124(cid:1)
The Simplest Popover You’ll Ever Create.......................................................................................................125(cid:1)
The Back End.................................................................................................................................................128(cid:1)
The Font Size Popover........................................................................................................................................131(cid:1)
Creating the GUI.............................................................................................................................................132(cid:1)
Making It Work...............................................................................................................................................133(cid:1)
The Stroke Width Popover..................................................................................................................................135(cid:1)
Paving the Way..............................................................................................................................................136(cid:1)
Creating the GUI.............................................................................................................................................136(cid:1)
Previewing the Stroke Width with a Custom View.........................................................................................137(cid:1)
Implementing the Controller..........................................................................................................................139(cid:1)
Making it Work...............................................................................................................................................139(cid:1)
The Dual-Action Color Popover...........................................................................................................................141(cid:1)
Creating a Simple Color Grid..........................................................................................................................142(cid:1)
Hooking Up the Grid.......................................................................................................................................144(cid:1)
Serving Two Masters.....................................................................................................................................146(cid:1)
Your Popover-Fu Is Strong..................................................................................................................................150(cid:1)
■Chapter 7: Video and Display Output...........................................................151(cid:1)
Displaying Multiple Videos..................................................................................................................................151(cid:1)
Creating the Video App Project......................................................................................................................152(cid:1)
Specifying Your Video Files............................................................................................................................152(cid:1)
Using the videoCell Outlet to Load the GUI.....................................................................................................153(cid:1)
Creating the VideoCell User Interface............................................................................................................155(cid:1)
Running the Video App...................................................................................................................................156(cid:1)
Outputting to an External Screen........................................................................................................................157(cid:1)
Extending the Video App to Handle an External Screen.................................................................................158(cid:1)
Implementing the VideoCell Delegate Method...............................................................................................161(cid:1)
Testing the External Screen Functionality.....................................................................................................162(cid:1)
Display Solutions................................................................................................................................................162(cid:1)
■Chapter 8: Split Views and Modal Modes....................................................163(cid:1)
The Split View Concept.......................................................................................................................................163(cid:1)
The Basics of Saving and Loading......................................................................................................................165(cid:1)
Document Management......................................................................................................................................168(cid:1)
Listing Files....................................................................................................................................................169(cid:1)
Creating and Deleting Files............................................................................................................................178(cid:1)
Renaming Files..............................................................................................................................................181(cid:1)
Implementing an About Panel in a Modal Way...................................................................................................185(cid:1)
Creating the Modal Web View Controller.......................................................................................................186(cid:1)
Displaying a Web Page..................................................................................................................................187(cid:1)
Integrating with the Dudel View Controller....................................................................................................188(cid:1)
Let's Split............................................................................................................................................................189(cid:1)
■Chapter 9: New Input Methods....................................................................191(cid:1)
Menu Additions...................................................................................................................................................191(cid:1)
Gesture Recognition............................................................................................................................................194(cid:1)
Adding Undo to Dudel....................................................................................................................................194(cid:1)
vii
■ CONTENTS
Resetting the Selected Tool’s State...............................................................................................................197(cid:1)
Keyboard Extensions and Replacements............................................................................................................197(cid:1)
Adding a Keyboard Button in Dudel...............................................................................................................198(cid:1)
Replacing the Keyboard.................................................................................................................................199(cid:1)
That’s All the Input You Need..............................................................................................................................208(cid:1)
■Chapter 10: Working with Documents.........................................................209(cid:1)
Passing Files to Another Application..................................................................................................................209(cid:1)
Adding a PDF-Sending Menu Action..............................................................................................................210(cid:1)
Preparing a File for Sending..........................................................................................................................211(cid:1)
Invoking the Document Interaction Controller...............................................................................................212(cid:1)
Receiving Files....................................................................................................................................................213(cid:1)
Registering As a Recipient.............................................................................................................................213(cid:1)
Testing the File-Receiving Feature................................................................................................................216(cid:1)
Retrieving File Information from Launch Options..........................................................................................217(cid:1)
Sending a Dudeldoc File................................................................................................................................218(cid:1)
Desktop Synchronization....................................................................................................................................219(cid:1)
Share and Share Alike........................................................................................................................................220(cid:1)
■Chapter 11: From iPhone to iPad.................................................................221(cid:1)
Introducing NavApp for iPhone...........................................................................................................................221(cid:1)
Creating the NavApp Project..........................................................................................................................222(cid:1)
Choosing the Active SDK................................................................................................................................226(cid:1)
Adding iPad to the Mix........................................................................................................................................227(cid:1)
Taking the Upgraded NavApp for a Spin........................................................................................................228(cid:1)
Conditional Behavior: Know Your Idioms.......................................................................................................229(cid:1)
Configuring the Main iPad GUI.......................................................................................................................231(cid:1)
Creating the Choice View Controller GUI for iPad..........................................................................................232(cid:1)
Implementing the Split View Delegate Methods............................................................................................233(cid:1)
Tweaking the Navigation Logic......................................................................................................................234(cid:1)
Enhancing the Main View with a No-Selection State.....................................................................................235(cid:1)
Running on Multiple Targets...............................................................................................................................237(cid:1)
Juggling iDevices................................................................................................................................................237(cid:1)
■Chapter 12: Additional Resources for iPad Development............................239(cid:1)
Logging in to the Mother Ship.............................................................................................................................239(cid:1)
iPad Development..........................................................................................................................................240(cid:1)
Objective-C and Cocoa Touch........................................................................................................................240(cid:1)
iPad App Deployment.....................................................................................................................................241(cid:1)
Learning from the Experts..................................................................................................................................241(cid:1)
Books.............................................................................................................................................................241(cid:1)
Tutorials and Code Examples.........................................................................................................................242(cid:1)
Designing User Interfaces for iPad Apps............................................................................................................242(cid:1)
Paper Prototyping..........................................................................................................................................243(cid:1)
Digital Mockups.............................................................................................................................................243(cid:1)
User Interface Icons.......................................................................................................................................244(cid:1)
Design Considerations and Inspirations.........................................................................................................244(cid:1)
Finding Answers in Online Forums.....................................................................................................................245(cid:1)
Holding the Future..............................................................................................................................................245(cid:1)
■Index............................................................................................................247
viii