Learn the Coding Secrets of Master iPhone Designers and Developers iPhone Cool Projects Gary Bennett | Wolfgang Ante | Mike Ash | Benjamin Jackson Neil Mix | Steven Peterson | Matthew “Canis” Rosenfeld DAVE MARK, SERIES EDITOR GARY BENNETT WOLFGANG ANTE MIKE ASH BENJAMIN JACKSON NEIL MIX STEVEN PETERSON MATTHEW “CANIS” ROSENFELD iPhone Cool Projects iPhone Cool Projects Copyright © 2009 by Gary Bennett, Wolfgang Ante, Mike Ash, Benjamin Jackson, Neil Mix, Steven Peterson, Matthew “Canis” Rosenfeld 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-2357-3 ISBN-13 (electronic): 978-1-4302-2358-0 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Clay Andres Development Editor: Douglas Pundick Technical Reviewers: Glenn Cole, Gary Bennett Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Michelle Lowman, Matthew Moodie, Jeffrey Pepper, Frank Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Copy Editor: Heather Lang Associate Production Director: Kari Brooks-Copony Production Editor: Laura Esterman Compositor: Dina Quan Proofreader: April Eddy Indexer: BIM Indexing & Proofreading Services Artist: April Milne Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or visit http://www.springeronline.com. For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley, CA 94705. Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://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 http://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 http://www.apress.com. You will need to answer questions pertaining to this book in order to successfully download the code. This book is dedicated to my wife, children, and friends who never stop believing in me. Also, I want to thank my friend Greg Stanley, who taught me the importance of thinking positive and being humble. This, I will always be grateful for. —Gary Bennett To my grandfather, Bernard Cohn, who handed down my first Apple computer. —Benjamin Jackson Neil Mix would like to thank his wife, Sarah, and his son, Henry, for encouraging him to take the time and energy to build Pandora Radio and contribute to this book. He would also like to thank his teammates at Pandora for being the best engineering team, period. Without them, Pandora Radio would not have been possible. —Neil Mix For my parents Pam & John: thanks for being my biggest fans. —Steven Peterson With love and thanks to Scary —Matthew “Canis” Rosenfeld [...]... // // // the color and shape of the center piece the colors and shapes of the surrounding circles the state of the running-out timer the number of lives left the amount of pieces set the state of the game (running, over, etc.) if blocked for animations to finish One variable is of special interest here, mBlocked, through which Formic uses the concept of blocking When animations are going on, the pieces... and what’s not, and alter accordingly In the following sections, you will learn to create Formic We’ll starting from an empty project and create the game object that contains all the game logic, the view controller that keeps all the views together and animates them Finally, we’ll create the custom view that sits in the background of all the views, accepts the player’s taps, and converts them into logical... dumb: they just know how to display themselves Most of them are simple UIImageViews, with one exception the background view draws the circles and knows about their positions Therefore, it also accepts the taps and translates the coordinates back into the tapped circles This input is then sent directly to the game object, bypassing the controller The main view controller is responsible for keeping all the. .. lucky to find these partners in Iconfactory They are some of the best designers in the field of icon and user interface design, and it’s an honor to work with them While I did all the programming on Frenzic, Gedeon Maheux designed the user interface, and David Lanham created the beautiful artwork The extensive web site was crafted by Anthony Piraino, while Craig Hockenberry and I wrote the code behind... the view Find the inspector panel (or open it from the menu by selecting Tools Inspector), and click the information icon (or press 4) to change the class to FormicView (see Figure 1-8) Save the change, then return to xScope Figure 1-8 Interface Builder file with Inspector to change the class of the view The final step to set up the structure of the application is to create the files for the game object... example, while the piece in the middle is moving out to a circle, the corresponding outer circle piece is still there and will start to fade out as the center piece reaches it But the game itself does not have intermediate states When the center piece has the same shape as in the tapped circle, both pieces will be renewed Therefore, during the animation, the views and the game logic are out of sync In... schedule the execution of a method at a later time It’s extremely easy and flexible to use—just tell the object itself which method to call, when, and with what argument The startGame method is used to create the introductory animation, where the pieces around the circle are moved in one after the other, and the center piece comes in at the end (see Figure 1-10) The starting of the timer is delayed to... covering the daunting but important task of multithreading The CPUs in the iPhone and iPod touch won’t be mistaken for those of the Mac Pro, but they pack enough power that frequently they are waiting for something to do Multithreading can be used to keep the user interface responsive while working on other tasks in the background Gary demonstrates how to do this, and highlights traps to avoid along the. .. at the Big Nerd Ranch In his spare time, he enjoys road trips and furthering his technical skills xiii Acknowledgments This book is a compilation of a lot of great work by some really smart authors They have focused and contributed their chapters based on areas of their expertise You get to benefit from the years of their expertise; enjoy it! I am so impressed by the fine people at Apress I believe their... prosaic integration of iPhone technologies He weaves Core Location, networking, XML, XPath, and SQLite into a solid and very useful application Games are great fun, but this is the type of application that makes the device so compelling for the non-gamer You’ve seen some of the pieces before; now you’ll see how to put them all together Software development can be hard Introductory books lay the foundation, . Learn the Coding Secrets of Master iPhone Designers and Developers iPhone Cool Projects Gary Bennett | Wolfgang Ante | Mike Ash | Benjamin Jackson Neil Mix | Steven Peterson | Matthew. covering the daunting but important task of multi- threading. The CPUs in the iPhone and iPod touch won’t be mistaken for those of the Mac Pro, but they pack enough power that frequently they are. contributed their chapters based on areas of their expertise. You get to benefit from the years of their expertise; enjoy it! I am so impressed by the fine people at Apress. I believe their books are the