About This eBook
ePUB is an open, industry-standard format for eBooks. However, support of ePUB and its many features varies across reading devices and applications. Use your device or app settings to customize the presentation to your liking. Settings that you can customize often include font, font size, single or double column, landscape or portrait mode, and figures that you can click or tap to enlarge. For additional information about the settings and features on your reading device or app, visit the device manufacturers Web site.
Many titles include programming code or configuration examples. To optimize the presentation of these elements, view the eBook in single-column, landscape mode and adjust the font size to the smallest setting. In addition to presenting code and configurations in the reflowable text format, we have included images of the code that mimic the presentation found in the print book; therefore, where the reflowable format may compromise the presentation of the code listing, you will see a Click here to view code image link. Click the link to view the print-fidelity code image. To return to the previous page viewed, click the Back button on your device or app.
iOS Core Animation
Advanced Techniques
Nick Lockwood
Upper Saddle River, NJ Boston Indianapolis San Francisco
New York Toronto Montreal London Munich Paris Madrid
Cape Town Sydney Tokyo Singapore Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact:
U.S. Corporate and Government Sales
(800) 382-3419
For sales outside the United States, please contact:
International Sales
Visit us on the Web: informit.com/aw
Copyright 2014 Pearson Education, Inc.
All rights reserved. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax your request to (201) 236-3290.
ISBN-13: 978-0-13-344075-1
ISBN-10: 0-13-344075-3
Editor-in-Chief
Mark Taub
Acquisitions Editor
Trina MacDonald
Angie Doyle
Development Editor
Michael Thurston
Managing Editor
Kristy Hart
Project Editor
Sara Schumacher
Copy Editor
Keith Cline
Proofreader
Sarah Kearns
Technical Reviewer
Mugunth Kumar
Publishing Coordinator
Olivia Basegio
For Zoe
About the Author
Nick Lockwood is head of iOS development at the digital agency AKQA in London, and a prolific developer of applications and open source libraries. He has been working with the iOS platform for the past four years, after making the switch from HTML5 web-app development. Nick first picked up a programming book in 1993 at a middle school rummage sale and hasnt looked back since. He lives in Sidcup with his wife and daughter.
Acknowledgments
I would like to thank my wife, Angela, and daughter, Zoe, for putting up with seeing even less of me than normal while I wrote this. Thanks to David Deutsch and P.J. Cook for their valuable feedback on the early manuscript. Thanks to Mugunth Kumar for generously agreeing to be my technical editor, and to all the staff at Pearson, particularly Michael Thurston, Sara Schumacher, Angie Doyle, Trina MacDonald, and Olivia Basegio, who between them somehow managed to extract a book from me in the space of four months. Thanks to my parents, for buying me my first programming book at the tender age of 12, and so starting me on the path to my eventual career. Finally, thanks to Kate for all the cups of tea!
Editors Note: We Want to Hear from You!
As the reader of this book, you are our most important critic and commentator. We value your opinion and want to know what were doing right, what we could do better, what areas youd like to see us publish in, and any other words of wisdom youre willing to pass our way.
You can e-mail or write me directly to let me know what you did or didnt like about this bookas well as what we can do to make our books stronger.
Please note that I cannot help you with technical problems related to the topic of this book, and that due to the high volume of mail I receive, I might not be able to reply to every message.
When you write, please be sure to include this books title and author as well as your name and phone or e-mail address. I will carefully review your comments and share them with the author and editors who worked on the book.
E-mail:
Mail: Trina MacDonald
Senior Acquisitions Editor
Addison-Wesley/Pearson Education, Inc.
75 Arlington St., Ste. 300
Boston, MA 02116
Reader Services
Visit our website and register this book at informit.com/register for convenient access to any updates, downloads, or errata that might be available for this book.
Preface
When Apple engineers created the iPhone, they faced a challenge: they needed to create a modern, fast, and fluid user interface, the likes of which had never been seen outside of a video game, and they needed to do it on mobile hardware that was a decade behind current desktops and laptops in terms of graphics performance.
They also had an opportunity: to rebuild AppKit (the Mac OS user interface framework) from the ground up using modern graphics technology without needing to maintain support for the legacy applications inherited from nearly 25 years of Macintosh and NeXTSTEP history.
Their solution was a private framework called Layer Kit, developed by the iPhone software team to provide a high-performance, hardware-accelerated animation and compositing library to replace the slower, Quartz-based software drawing used by AppKit. This framework actually debuted first on Mac OS 10.5 under the name Core Animation, shortly before the iPhone was announced.
Core Animation is not just a set of functions for performing animations; it lies at the very heart of iOS, powering everything you see on screen. Even if you never invoke it explicitly, you are using it