Ios Core Animation

Ios Core Animation

iOS Core Animation 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 Editor-in-Chief are claimed as trademarks. Where those designations appear in this book, and the pub- Mark Taub lisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. Acquisitions Editor The author and publisher have taken care in the preparation of this book, but make no Trina MacDonald expressed or implied warranty of any kind and assume no responsibility for errors or Angie Doyle 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. Development Editor The publisher offers excellent discounts on this book when ordered in quantity for bulk Michael Thurston 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 Managing Editor interests. For more information, please contact: Kristy Hart Project Editor U.S. Corporate and Government Sales Sara Schumacher (800) 382-3419 [email protected] Copy Editor Keith Cline For sales outside the United States, please contact: Proofreader International Sales Sarah Kearns [email protected] Technical Reviewer Visit us on the Web: informit.com/aw Mugunth Kumar Copyright © 2014 Pearson Education, Inc. Publishing Coordinator All rights reserved. This publication is protected by copyright, and permission must be Olivia Basegio 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, photocopy- ing, 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 ❖ For Zoe ❖ Contents at a Glance I: The Layer Beneath 1 The Layer Tree 2 The Backing Image 3 Layer Geometry 4 Visual Effects 5 Transforms 6 Specialized Layers II: Setting Things in Motion 7 Implicit Animations 8 Explicit Animations 9 Layer Time 10 Easing 11 Timer-Based Animation III: The Performance of a Lifetime 12 Tuning for Speed 13 Efficient Drawing 14 Image IO 15 Layer Performance Table of Contents Preface Audience and Material Book Structure Before We Begin I: The Layer Beneath 1 The Layer Tree Layers and Views CALayer Parallel Hierarchies Layer Capabilities Working with Layers Summary 2 The Backing Image The contents Image contentsGravity contentsScale masksToBounds contentsRect contentsCenter Custom Drawing Summary 3 Layer Geometry Layout anchorPoint Coordinate Systems Flipped Geometry The Z Axis Hit Testing Automatic Layout Summary 4 Visual Effects Rounded Corners Layer Borders Drop Shadows Shadow Clipping The shadowPath Property Layer Masking Scaling Filters Group Opacity Summary 5 Transforms Affine Transforms Creating a CGAffineTransform Combining Transforms The Shear Transform 3D Transforms Perspective Projection The Vanishing Point The sublayerTransform Property Backfaces Layer Flattening Solid Objects Light and Shadow Touch Events Summary 6 Specialized Layers CAShapeLayer Creating a CGPath Rounded Corners, Redux CATextLayer Rich Text Leading and Kerning A UILabel Replacement CATransformLayer CAGradientLayer Basic Gradients Multipart Gradients CAReplicatorLayer Repeating Layers Reflections CAScrollLayer CATiledLayer Tile Cutting Retina Tiles CAEmitterLayer CAEAGLLayer AVPlayerLayer Summary II: Setting Things in Motion 7 Implicit Animations Transactions Completion Blocks Layer Actions Presentation Versus Model Summary 8 Explicit Animations Property Animations Basic Animations CAAnimationDelegate Keyframe Animations Virtual Properties Animation Groups Transitions Implicit Transitions Animating Layer Tree Changes Custom Transitions Canceling an Animation in Progress Summary 9 Layer Time The CAMediaTiming Protocol Duration and Repetition Relative Time fillMode Hierarchical Time Global Versus Local Time Pause, Rewind, and Fast-Forward Manual Animation Summary 10 Easing Animation Velocity CAMediaTimingFunction UIView Animation Easing Easing and Keyframe Animations Custom Easing Functions The Cubic Bézier Curve More Complex Animation Curves Keyframe-Based Easing Automating the Process Summary 11 Timer-Based Animation Frame Timing NSTimer CADisplayLink Measuring Frame Duration Run Loop Modes Physical Simulation Chipmunk Adding User Interaction Simulation Time and Fixed Time Steps Avoiding the Spiral of Death Summary III: The Performance of a Lifetime 12 Tuning for Speed CPU Versus GPU The Stages of an Animation GPU-Bound Operations CPU-Bound Operations IO-Bound Operations Measure, Don’t Guess Test Reality, Not a Simulation Maintaining a Consistent Frame Rate Instruments Time Profiler Core Animation OpenGL ES Driver A Worked Example Summary 13 Efficient Drawing Software Drawing Vector Graphics Dirty Rectangles Asynchronous Drawing CATiledLayer drawsAsynchronously Summary 14 Image IO Loading and Latency Threaded Loading GCD and NSOperationQueue Deferred Decompression CATiledLayer Resolution Swapping Caching The +imageNamed: Method Custom Caching NSCache File Format Hybrid Images JPEG 2000 PVRTC Summary 15 Layer Performance Inexplicit Drawing Text Rasterization Offscreen Rendering CAShapeLayer Stretchable Images shadowPath Blending and Overdraw Reducing Layer Count Clipping Object Recycling Core Graphics Drawing The -renderInContext: Method Summary About the Author Nick Lockwood is head of iOS development at the digital agency AKQA in London, and a pro- lific developer of applications and open source libraries. He has been working with the iOS plat- form 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 hasn’t 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! Editor's 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 we're doing right, what we could do better, what areas you'd like to see us publish in, and any other words of wisdom you're willing to pass our way. You can e-mail or write me directly to let me know what you did or didn't like about this book—as 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 book's 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: [email protected] 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 implicitly every time you display a view or transition from one screen

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    27 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us