Core.Animation.for.Mac.OS.X.and.the.iPhone
Prepared exclusively for Ki Wan Han
What readers are saying about
Core Animation for Mac OS X and the iPhone
Animation isn’t “eye candy.” It’s about making GUI experiences less arbitrary and more comprehensible. The developers of Apple’s Core Animation get this, and so does Bill Dudney. His book offers a deep, thoughtful guide to the API and the ideas behind it.
Chris Adamson
Author of QuickTime for Java: A Developer’s Notebook
It’s great to see a book for Mac developers that focuses on one topic and does it well. Its pace is excellent and will allow you to have sim- ple animations running in minutes. As the book goes deeper into its subject, it presents you with just the right amount of information to understand what you are doing so you don’t feel like you are just fol- lowing instructions, yet it never turns into a dry reference manual that overloads you with unnecessary detail.
Steve (“Scotty”) Scott
The Mac Developer Network (http://www.macdevnet.com)
Finally! The comprehensive how-to guide we’ve been waiting for on all
our Core Animation needs.
Eric Wing
Developer
As an early adopter of Core Animation technology for the creation of Videator, I have but one regret: if only I had had Bill’s book, I would have finished it in half the time!
Andrew Stone
CEO, stone.com
Prepared exclusively for Ki Wan Han
Core Animation is an exciting new library for developers on both the iPhone and the Mac. Bill Dudney’s book makes a great companion for Cocoa programmers looking to add it to their bag of developer tricks.
Daniel Jalkut
Founder, Red Sweater Software
Apple has abstracted the power of the underlying graphics engine that has been in Mac OS X into a framework we can all use to improve the user experience. Bill Dudney has given us a road map to that frame- work just as Apple is providing the next new platform: the iPhone SDK. Now it’s time for us to make beautiful code.
Bill Shirley
Senior Software Architect, Frazer, Ltd.
Core Animation for Mac OS X and the iPhone is that all-too-rare kind of how-to engineering book that is both deeply informative and enjoy- able to read. If you want your app to remain competitive in the Mac marketplace, a mastery of Core Animation is crucial. This book will go a long way to getting your UI development skills where they need to be in order to take advantage of the most excited trends in Mac OS on the desktop, the iPhone, and beyond.
John C. Fox
Creator of MemoryMiner
The focus on the principles of animation and smooth learning curve makes Core Animation for Mac OS X and the iPhone a perfect compan- ion in your transition to the new framework.
Danny Greg
Developer, Realmac Software
This book is a great companion to Apple’s programming guide. Using this book I was able to easily add user interface animations to my Cocoa application in just a few nights.
Bill Nalen
Cocoa Developer
Prepared exclusively for Ki Wan Han
Prepared exclusively for Ki Wan Han
Core Animation for Mac OS X and the iPhone Creating Compelling Dynamic User Interfaces
Bill Dudney
The Pragmatic Bookshelf
Prepared exclusively for Ki Wan Han
Raleigh, North Carolina Dallas, Texas
Many of the designations used by manufacturers and sellers to distinguish their prod- ucts are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at
http://www.pragprog.com
Copyright © 2008 Bill Dudney.
All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmit- ted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher.
Printed in the United States of America.
ISBN-10: 1-934356-10-7 ISBN-13: 978-1-934356-10-4 Printed on acid-free paper. P1.0 printing, October 2008 Version: 2008-10-3
Prepared exclusively for Ki Wan Han
Contents
1 Introduction 10
1.1 WhatIsCoreAnimation?.................. 11
1.2 InThisBook......................... 12
1.3 Acknowledgments...................... 14
2 Cocoa Animation 17
2.1 MovingWithoutAnimation................. 17
2.2 IntroducingCocoaAnimation ............... 20
2.3 AnimationandtheAnimatorProxy . . . . . . . . . . . . 23
2.4 AnimationandInterpolation................ 24
3 Animation Types
3.1 Basic Animation . . . .
3.2 Keyframe Animations .
3.3 Grouping Animations .
3.4 Animating Transitions
3.5 CustomAnimationandInterpolation. . . . . . . . . . . 43
4 Animation Timing
4.1 Animation Timing Curves
4.2 Cocoa Animation Timing .
4.3 Chaining Animations . . .
5 Layer-Backed Views
45
................. 45 ................. 52 ................. 54
58
................... 28 ................... 29 ................... 35 ................... 40
5.1 TheRoadAhead......
5.2 View and Layer Hierarchy
5.3 ViewShadow........
5.4 ViewAlpha.........
5.5 RotatedViewsandControls ................ 63
5.6 Layer Backing and Performance Concerns . . . . . . . 65
Prepared exclusively for Ki Wan Han
................. 59 ................. 59 ................. 61 ................. 63
28
CONTENTS 8
6 Filtered Views 68 6.1 ViewFilters.......................... 69 6.2 BackgroundFilters ..................... 71
6.3 Content Filters . . . .
6.4 Compositing Filters .
7 Core Animation
7.1 Layer-Hosting Views
7.2 Forming UIs with Layers . . . .
7.3 Organizing Layers in Trees . . .
7.4 Layer Layout with Constraints
8 Core Animation Layers
8.1 Animation Types and Layers . .
8.2 AnimationTiming........
8.3 RotationandLayers.......
8.4 FiltersandLayers........
8.5 ManagingaLayer’sContents ............... 109
8.6 DrawinginLayers...................... 110
8.7 TiledLayers ......................... 111
8.8 AnimationsandActions .................. 115
9 Layer Scrolling and Geometry 118 9.1 ScrollingLayers ....................... 118 9.2 GeometryProperties .................... 124 9.3 Layersin3DSpace ..................... 132
10 Layers in 3D 133 10.1 AddingDepthtoLayerAppearance . . . . . . . . . . . . 133 10.2 CustomLayerLayout.................... 137 10.3 3DTransformations .................... 143
11 Media Layers 149 11.1 QuickTimeLayers...................... 149 11.2 Quartz Composer Composition Layers . . . . . . . . . . 158 11.3 OpenGLLayers ....................... 161
12 Core Animation on the iPhone 165 12.1 CocoaTouch......................... 165 12.2 LayersandAnimations................... 168 12.3 OpenGLLayers ....................... 174
...... ......
.............. 73 .............. 78
81
.............. 82 .............. 84 .............. 85 .............. 90
96
......
.............. 96 .............. 101 .............. 107 .............. 109
Prepared exclusively for Ki Wan Han
Report erratum this copy is (P1.0 printing, October 2008)
CONTENTS 9
Bibliography 178 Index 180