_creating_ios_ui,_animations,_and _gestures

265 238 0
_creating_ios_ui,_animations,_and _gestures

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

From Idea to App Creating iOS UI, Animations, and Gestures Shawn Welch From Idea to App: Creating iOS UI, Animations, and Gestures Shawn Welch New Riders 1249 Eighth Street Berkeley, CA 94710 510/524-2178 510/524-2221 (fax) Find us on the Web at: www.newriders.com To report errors, please send a note to errata@peachpit.com New Riders is an imprint of Peachpit, a division of Pearson Education Copyright © 2011 by Shawn Welch Project Editor: Michael J Nolan Development Editor: Margaret Anderson/Stellarvisions Production Editor: Tracey Croom Tech Editor: Scott Fisher Copyeditor: Gretchen Dykstra Proofreader: Jan Seymour Indexer: Rebecca Plunkett Cover Designer: Charlene Charles-Will Interior Designer: Kathleen Cunningham Compositor: Kim Scott, Bumpy Design Notice of Rights All rights reserved No part of this book may be reproduced or transmitted in any form by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher For information on getting permission for reprints and excerpts, contact permissions@peachpit.com Notice of Liability The information in this book is distributed on an “As Is” basis without warranty While every precaution has been taken in the preparation of the book, neither the author nor Peachpit 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 instructions contained in this book or by the computer software and hardware products described in it Trademarks Apple, iPod, iTunes, iPhone, iPad, and Mac are trademarks of Apple, Inc., registered in the United States and other countries 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 Peachpit was aware of a trademark claim, the designations appear as requested by the owner of the trademark All other product names and services identified throughout this book are used in editorial fashion only and for the benefit of such companies with no intention of infringement of the trademark No such use, or the use of any trade name, is intended to convey endorsement or other affiliation with this book ISBN 13: 978-0-321-76555-0 ISBN 10: 0-321-76555-9 987654321 Printed and bound in the United States of America Dedication To my parents, Dave and Kelly Welch For all you have sacrificed to my benefit, for all of the hours you have invested in my life, my success is your success Acknowledgements Huge thanks to Dave Moser and Scott Kelby at Kelby Media Group for allowing me to perfect my craft and grow as an iOS developer with their team, and to Scott for taking the time to write the foreword for this book I really appreciate the advice and support they’ve given me over the years Thanks to Matt Kloskowski, Dave Cross, RC Concepcion, Corey Barker, Paul Wilder, Erik Kuna, Tommy Maloney, and the rest of the fine folks at NAPP for providing valuable feedback on earlier versions of some of my apps Thanks as well to Nancy Massé for always being helpful and for first introducing me to Dave Moser and Scott Kelby Thanks to Scott Cowlin, who first supported my crazy idea of writing a technical book targeted at designers, and to Michael Nolan, Margaret Anderson, Gretchen Dykstra, and the rest of the staff at Peachpit Press for helping me turn that idea into an incredible text Thanks to Scott “Fish” Fisher, my tech editor, whose attention to detail in the code blocks caught even the smallest typo A very special thanks to Alan Cannistraro, Evan Doll, Stanford University, and Apple for teaching and encouraging me and other iOS developers, and for making their courses, lectures, and learning material available for free online Thanks to Cholick for being a daily sounding board for my half-baked notions and crazy ideas for nearly four years I’m grateful to my parents, Dave and Kelly Welch, as well as my brothers and their families—Eric and his wife, Gretchen; Danny and his wife, Katie; and Kyle—for keeping me humble and reminding me of the humor in life And, of course, thank you to everyone who uses my apps, my Twitter followers, my Facebook friends, and NAPP members across the globe The success of an iOS designer/developer comes from experience; your feedback combined with your daily use of my apps gave me the experience I needed to write this book Thank you ­— Shawn Welch iv Foreword Foreword Picture an iPhone in your mind OK, now picture any other smartphone out there Visualize this other smartphone until you have a really clear image of it Got it? OK, good My guess is that whichever smartphone you pictured—regardless of the brand or manufacturer—it has a touchscreen, a built-in accelerometer, and rows of glassy-looking icons with a wallpaper photo behind them I also bet that you flick the screen with your finger to move through your photos, right? Even though it’s not an iPhone, it still works and even looks like an iPhone Apple did it so right when they introduced the original iPhone that nearly every new smartphone or tablet that comes out today is just another copy of what Apple has already done But there’s an excitement around the iPhone and iPad that no other smartphone or tablet manufacturer has been able to capture What sets iOS apart is the apps Apps are it They’re “it.” And while other smartphones and tablets now have some apps, too, they’re not iOS apps, and neither the developers nor the end users of those other apps are rewarded like the people who design, and use, iOS apps The iPhone itself is a beautifully designed piece of technology So is the iPad Hold either of them in your hand and you can’t help but like it But it’s the apps that make you fall in love Everybody’s iPhone or iPad has basic apps on it—Calendar, Maps, Weather, Calculator, and so on—but once you start adding third-party apps, it becomes your iPhone Your iPad It’s personal because your apps reflect your life, your personality, and your passions Apps have changed how we live our lives, how we run our businesses, and what we in our free time Imagine how powerful you would be if you could create apps that touch people, empower them, engage them, let them create and communicate in ways they never knew before Foreword Well, you’re about to get that power Best of all, you’ll learn how to unlock that power from one of the most talented, passionate, and gifted iOS programmers out there today I know, because he’s built numerous apps for my own company, and the number one comment we hear from everybody is, “Wow! Where did you find this guy!” Shawn understands the end user in a way that few developers ever on any platform He uses apps the way we do, and looks at them from a user’s perspective, so people feel at home using his apps They’re intuitive They’re fun And, like Apple itself, Shawn knows that how an app looks matters In this book, Shawn gives you the tools to make your vision a reality, to design apps that people want to use and tell their friends about He unlocks the secrets to what makes a great app and shows you exactly how to build them Whether you’re a designer who wants to bring your ideas to life, or a developer who wants to learn the power of great design, you’re holding the one book that will open that door for you All you have to is turn the page I wish you the very best on this exciting new adventure, and I’m glad to see you’ve picked such a great guide to take you there Now go design some really great stuff! Scott Kelby Author of The iPhone Book v vi Table of Contents Table of Contents Part I Introduction Getting Started with iOS Why Are We Here? iOS Devices iOS Development Tools and Resources Quick Tips: iOS Development Strategies 11 Guiding Principles 16 What Makes an iOS App? 19 iOS: The Big Picture 20 Application Types 26 iOS App Blueprint 29 Introduction and “Hello, World!” Creating an Xcode Project 29 Conclusion 35 Part II The Basics of iOS User Interfaces 37 Physical Hardware 39 Physical Input Devices 40 Device Orientation 45 iOS Coordinate System 48 Preparing Image Assets for Multiple Displays 49 Basic User Interface Objects 51 UIKit and Foundation 52 iOS Views 53 UIKit 57 User Interface Controllers and Navigation 71 What Is a Controller? 72 View Controllers, Navigation, and Modal Views 76 Table of Contents User Interface Buttons, Inputs, Indicators, and Controls Alert Dialogs and Action Sheets 89 90 Indicators 94 Controls and Buttons iOS App Blueprint The Basics Creating UIViewControllers Adding UIControls to Each Tab Connecting UI Controls to a Controller Create a UITabBarController Part III Designing Custom iOS User Interface Objects Creating Custom Icons, Launch Images, and Buttons 96 107 108 109 112 114 115 117 App Icons 118 Launch Images 120 Custom UI Buttons 122 Creating Custom UIViews and UIViewControllers 131 Custom UIViewControllers 132 Custom UIViews 142 Creating Custom Table Views 149 UITableViewController 150 UITableView Appearance 152 Creating Custom Cells 156 Moving, Deleting, and Inserting Rows 158 iOS App Blueprint 162 Custom iOS UI Overview 162 Changes to the First Tab 162 vii viii Table of Contents Part IV  Animating Your UI 171 10 Introduction to iOS Animations 173 About Animations Using UIKit 174 UIView Animation Blocks 175 System-Provided Animations 180 11 Creating Custom iOS Animations 185 About Core Animation 186 Core Animation Types 188 Getting Started with Core Animations 189 Keyframe Animations 191 Animation Transitions 195 3D Transforms 196 iOS App Blueprint 199 Custom Animations Overview 199 Animations of CountdownViewController 204 Part V  Human Interaction: Gestures 207 12 Introduction to iOS Gestures 209 Understanding Apple-Defined Gestures 210 Gestures and UIKit 213 13 Creating Custom iOS Gestures 221 Detecting Touches in a UIView 222 Gesture Recognizers 227 Motion Gestures 237 iOS App Blueprint 242 Custom Gestures Overview 242 Note from the Author 246 Index 247 Part I Introduction Getting Started with iOS What Makes an iOS App? 19 iOS App Blueprint Introduction and “Hello, World!” Creating your first iOS app 29 242 iOS App Blueprint   Custom Gestures iOS App Blueprint Custom Gestures We just learned how to use gestures to add unique functions to your iOS apps Unlike most desktop applications, iOS apps are not limited to input driven by buttons or controls Physical motion of the device itself or multi-touch gestures on the device screen can provide a truly immersive experience for users Get the Code ➠➠➠ You can build this app as we go, or go to fromideatoapp.com/ downloads/blueprints to download the completed project file FI2ADemo and follow along Overview Our goal for this blueprint is simple We want to let the user drag the countdown controller (added in the previous blueprint) across the screen using two fingers We’ve talked about two methods for tracking a user’s finger on the screen: 77 Implementing touchesBegan, touchesMoved, and touchesCancelled in HUDView (a UIView subclass) 77 Adding a UIPanGestureRecognizer to the countdown timer from the T2_TableViewController class Now we need to consider how and why to implement one method or the other As you know, we downloaded the CountdownViewController and HUDView classes in the previous blueprint Having not written the code yourself, it might not be the best idea to start overriding methods to add the dragging behavior We’re also adding the countdown view to the navigation controller of the T2_TableViewController The last thing we want to is isolate controller methods inside a view, especially when we’re already adding the view to another controller’s associated view and now our own (self.navigationController.view) Overview In light of this, it makes sense to add this function to the CountdownViewController by creating a UIPanGestureRecognizer and associating it to the view at the time of creation This way the CountdownView­ Controller remains untouched, giving us the ability to reuse this class in the future when we might not want the user to move it around and our controller class maintains control over the UI’s behaviors To give the user the ability to drag the countdown timer around the screen using a UIPanGestureRecognizer, we’ll perform the following steps: Create a CGPoint reference in the T2_TableViewController header file to store the initial value of the touch event and define a method for handling the actual panning gesture Create a UIPanGestureRecognizer and associate it with the CountdownViewController’s view before presenting it on the screen Reposition the CountdownViewController’s view based on the relative motion of the panning gesture Step First we need to add two things to the T2_TableViewController header file: a CGPoint to track where the panning motion starts, and a handler method to take care of the actual panning action By now, you should be comfortable creating new instance variables and defining new methods, so let’s add the following code block: #import #import "CountdownViewController.h" @interface T2_TableViewController : UITableViewController { CGPoint firstPoint; } - (void)panCountdownHUD:(UIPanGestureRecognizer*)panGesture; @end 243 244 iOS App Blueprint   Custom Gestures In line 4, we add a variable named firstPoint to the class interface, and in line we declare the panning gesture method Notice that in line 7, the panning action method receives as a parameter the panning gesture itself We’ll use this to maintain reference to the countdown view as it is moved Step The next step is to actually create the panning gesture Because we’re making the countdown view controller in the didSelectRowAtIndexPath method of T2_TableViewController, it makes sense to create our gesture here as well We simply allocate a new variable, define the number of touches required, and then associate it with the CountdownControllerView’s view We’ll add the following code block to the didSelectRowAtIndexPath method immediately following the creation of count, our local variable of CountdownViewController: // Create a new UIPanGestureRecognizer // Set the target of the gesture action to self // Set the action method to panCountdownHUD: UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panCountdownHUD:)]; // Define the number of touches required pan.minimumNumberOfTouches = 2; // Add the panning gesture recognizer to the 10 // view of our countdown clock and then 11 // release our panning gesture (memory management) 12 [count.view addGestureRecognizer:pan]; 13 [pan release]; Overview 245 In line 4, we create the new UIPanGestureRecognizer, assigning the target as self (T2_TableViewContoller) and the action as panCount downHUD: Next, in line we define the number of touches required, followed by line 12 where we associate the gesture recognizer with the countdown view controller’s view In line 13, we maintain proper memory management by releasing the pan gesture Step The last step is to implement the panCountdownHUD method so that as the user drags the view with two fingers, the position of the countdown view controller’s view tracks to follow We this by storing the location of the view when the gesture first begins, then calculating the difference between where the gesture is now and where it started Finally, we apply a new center to the view based on these calculations - (void)panCountdownHUD:(UIPanGestureRecognizer*)panGesture{ // Check the gesture recognizer state // if([panGesture state] == UIGestureRecognizerStateBegan) If things have just begun, save the current location of the countdown view controller's view firstPoint = panGesture.view.center; // Calculate the difference (x,y) based on the current // 10 CGPoint diff = [panGesture position of the panning motion translationInView:self.navigationController.view]; 11 12 // Calculate a new center based on our original center 13 // 14 CGPoint newCenter = CGPointMake(firstPoint.x + diff.x, and the difference created by our panning motion firstPoint.y + diff.y); 15 16 // Apply the new center to our countdown view controller's view 17 panGesture.view.center = newCenter; 18 } 246 iOS App Blueprint   Custom Gestures And that’s it! If you build and run the project, you should be able to reposition the countdown view controller by dragging it with two fingers If you are using the iOS Simulator, go back and change the touches required from two to one This will trigger the panning gesture when only one finger is used Because the iOS Simulator can’t simulate multiple touches during a panning gesture, you’ll only see the two-­ finger panning gesture on an actual iOS device You can see the added advantage of using gestures to improve usability and add functions Remember, we also learned how to implement the pinch-zoom gesture If you want to take this project further by adding a pinch-to-scale up or down gesture, you could so using UIPinch­ GestureRecognizer You could also implement a swipe-to-cancel feature using the UISwipeGestureRecognizer Feel free to download the project files and build on them Get the Code ➠➠➠ Download FI2ADemo at fromideatoapp.com/downloads/blueprints to see samples from this blueprint and more Note from the Author Thank you for reading From Idea to App: Creating iOS UI, Animations and Gestures! I truly hope you enjoyed the book and learned something along the way Be sure to check out the resources that are available at fromideatoapp.com and not hesitate to contact me with questions and/or comments either from the book’s website (fromideatoapp.com) or directly @shawnwelch (twitter.com/shawnwelch) If after reading the book you decide to make an app, let me know! I’d love to see what you guys create, I might even be your first customer :) Keep it simple, keep it effective, make it memorable —Shawn Index Symbols @property method, 137 @synthesize method, 137 | symbol, 85, 234 A accelerometer, 43–44, 238 action sheets defined, 90, 92–93 styles for, 93 using action dialogs vs., 92 aesthetic integrity, 17 alert dialogs, 90–92 animation, 171–206 about, 173 along paths, 193–195 card flips, 196–198, 222 custom vs system-provided, 85 customizing countdown timer, 199–206 developing UIView blocks of, 175–177 implicit vs explicit, 188–189 including Quartz library in projects, 189–190 keyframe, 191–195 modal view screen, 86–87 spinner, 94–95 system-provided, 85, 180–183 types of transitions, 195–196 UIView methods for, 178 using Core Animation, 190–191 using UIKit for, 174–175 animationWithKeyPath method, 97 app files, 24 AppDelegate.m file, 32–33 Apple See also iTunes App Store Human Interface Guidelines, 16–18 memory management documentation, 16 Multimedia Programming Guide, 42 registering as developer with, 7, review guidelines for apps, Application Sandbox, 21–22 apps See developing apps; iOS apps architecture Cocoa Touch base frameworks, 52 iOS, 20 MVC, 12–13, 71, 150 arrow direction, 85 audio session properties for, 42 supported files for, 24–25 volume controls, 43 B blend modes for images, 147–148 blueprint project files about, 29 animating countdown timer, 199–206 creating UIViewControllers, 107–114 customizing UI tabs, 162–170 developing custom gestures, 242–246 downloading, 29 “Hello, World!” project, 29–35 bonus materials, 241 bounds property, 56 buttons alert dialog, 90, 92 Contact Add, 101–102 custom UI, 122–129 Detail Disclosure, 101 developing custom UI, 122–123 Info, 101 retina display and custom, 129 Rounded Rectangle, 100, 126–127 setting states for UIButtons, 125–129 styles of UIButton, 100–101 system-provided, 97–100 tab bar, 99 toolbar, 70, 97–99 UIBarButtonItem, 124–125 C CAKeyframeAnimation, 192–193 CALayer, 187–188 camera-enabled apps, 42–43 canBecomeFirstResponder method, 239 CATransitions, 195–196 cells See also table views about, 68–69 accessory view styles, 155 creating custom, 156–158 managing table, 153–154 reusing, 155 CGRect, 56 classes See also subclasses; and specific classes about UIViewController, 72–73 available in UIKit, 58 consistent naming of, 135 Core Animation, 188 creating in Cocoa Touch, 133–134 UIViewController, 72–79 Cocoa Touch creating classes in, 133–134 subclassing custom UIViews, 143–144 UIKit and Foundation in, 52 248 Index color action dialog button, 92 maintaining animation, 192 setting table background, 153 consistency, 17 Contact Add button, 101–102 contentView property, 154, 156–158 controllers See view controllers controls adding to sample app, 109–111 connecting to controller, 112–113 page, 95 pickers, 102–103 reorder, 159–160 segmented, 103–104 sliders, 105 switches, 104 UIControl class and, 96 coordinate system, 48–49, 54 Core Animation about, 173–174 animating objects with, 190–191 applying 3D transforms, 196–198 CALayer of, 187–188 classes for, 188 custom view animation with, 186–187 implicit vs explicit animations, 188–189 keyframe animation with, 191–195 using CATransitions, 195–196 Core Graphics, 144, 173 countdown timers about, 103 animating, 204–206 dragging around screen, 243–246 implementing CountdownViewController, 199–204 custom gestures See gestures customizing UI objects See also table views buttons, 122–129 creative custom buttons, 127–129 custom UIViewControllers, 132–142 designing icons, 118 developing custom UIViews, 142–148 D data app folders for, 21–22 implementing UITableView data source methods, 169–170 loading from Internet, 64 MVC model and, 12 date and time pickers, 102–103 delegates calling, 63 configuring view controller, 201–202 implementing, 169–170 inserting and deleting rows with UITableView, 160–161 UITableViewController protocols for, 150–152 Detail Disclosure button, 101 DetailViewController.h file, 165, 167, 170 developers designing and developing apps, 51 downloading iOS tools, iOS SDK for, 7, memory management techniques for, 14–16 registering as Apple, developing apps See also Human Interface Guidelines; user interface; and specific elements awareness of workflows, 22, 45 building in Xcode, 137–138 calling delegates, 63 characteristics of mobile apps, 20–21 creating and running Xcode projects, 31–32 customizing icons, 118 defining audio session properties, 42 designing and, 51 dismissing UIAlertViews and UIActionSheets, 90 enabling camera sessions, 42–43 files used in, 23–24 handling automatic rotation, 47, 72 launch images, 120–122 list of home directory folders, 21 memory management, 14–16 Model-View-Controller architecture for, 12–13 planning for custom cells, 158 programming target actions and events, 96 responding to gestures, 209 reusing views, 55, 236–237 strategies for, 11–16 subclassing, 13–14 support for multitasking, 22–23 text field design, 105–106 using Mac OS X vs iOS, 20–23 using UI elements consistently for, 100 working with UIGestureRecognizer, 237 zooming in scroll views, 219 devices See HIDs; iOS devices; and specific devices direct manipulation, 17 displays See also views iPad action sheet, 92–93 iPhone retina, 48, 129 Multi-Touch device, 41 resolutions and coordinate systems for, 49 double-tap gesture, 212, 216 downloading Apple memory management documentation, 16 blueprint project files, 29 iOS tools, Index Multimedia Programming Guide, 42 sample app with MVC architecture, 13 drag flick vs., 211 moving countdown timers with, 243–246 single-finger, 210–211 triggering gesture recognition for, 233 drawRect function overriding, 156–157 refreshing, 143–144 setNeedsDisplay vs., 55 drill-down navigation, 79–81 E embedded views, 65 events detecting end of, 226 methods and properties tracking touch, 223 moved touch, 225 programming target actions and, 96 recognizing shake, 239–241 triggering touchesBegan, 223–225 two gesture recognizers for touch, 228–229 explicit animations, 188–189 F feedback, 18 files See also blueprint project files; and specific file types adding resources to apps, 24 downloading blueprint project, 29 generating and editing AppDelegate.m, 32–33 localization, 25 nib, 23, 25, 74, 132 pair naming conventions for, 49–50 resource, 24–25 specs for app icon, 119 supported image, 24–25, 60–61 types of app, 23–24 video and audio, 24–25 flick, 211 folders Resources, 24 system-created, 21–22 Foundation framework, 52 frame property, 56 frameworks See also UIKit Cocoa Touch base, 52 defined, 23 full-screen apps, 28 G gesture recognizers See also UIGestureRecognizer about, 221–222 alternative for touchesBegan method, 236, 242 249 associating view with multiple, 228–229 detecting user input with, 227–229 panning, 233 pinch gesture, 230–231 press-and-hold, 235–236 rotation, 231–232 states for, 228–229 tap, 229–230 UISwipeGestureRecognizer, 234 gestures See also gesture recognizers blueprint for custom, 242–246 configuring for UIScrollView, 214–219 defining new, 221–222 designing apps for, 209 detecting touches in UIView, 222–227 header code for implementing custom, 237 motion, 237–241 properties for UIScrollView, 215 types of, 210–213 user alternatives for, 214 graphics blend modes for images, 147–148 drawing paths for, 145–146 Quartz 2D features for, 132, 144–145 transforms, 146 gyroscope, 43, 238 H h (header) files about, 23–24 creating UIViewController, 134–135 custom subclass, 163–164 implementing custom gestures in, 237 preparing DetailViewController, 165, 167, 170 required for UIView subclasses, 143 ScrollViewController, 217–218 table view, 155–156 “Hello, World!” project, 29–35 adding views to, 56–57 creating and saving, 31–32 editing in Xcode, 32–35 HIDs (human interface devices) about, 40 accelerometer and gyroscope, 43–44 defining audio session properties, 42 developing apps for camera, 42–43 Home button, 44–45 Mute switch, 44 Power/Lock button, 45 volume controls, 43 high-resolution image files, 49–50 Home button, 44–45 HUDView, 200–201 human interface devices See HIDs 250 Index Human Interface Guidelines action sheets, 93–94 alert dialog standards, 91–92 Apple standards for, 16–18 application types, 26–28 custom artwork, 117 developing custom UI buttons, 122–123 gestures and, 209 using system-provided buttons, 97 I IBOutlet identifier, 138, 140 icons, 118–120 images blend modes for, 147–148 custom tab bar, 123–124 editing, 118 formats of UIImage and UIImageView objects, 60–61 icon specs for, 119–120 launch, 120–122 naming, 49–50, 121, 124 placing in project folder, 164 resolution file pairs for, 49–50 supported files for, 24–25 implicit animations, 188–189 indicators, 94–95 Info button, 101 info property list (info.plist), 26, 120 inheritance subclassing and, 13–14 UIView object, 53 input See keyboard Instruments, 7, 11 Interface Builder about, 7–9 about IBOutlet identifier, 138, 140 downloading, nib file documents in, 25, 74 using Xcode files in, 138–140 iOS See also iOS apps; iOS devices Application Sandbox of, 21–22 architecture of, 20 development tools and resources for, 7–11 features of, 5–7 gestures in, 209–213 Interface Builder, 7–9 iPhone OS origins of, 5–6, 20 Mac OS X vs., 20–23 multitasking in, 22–23 recognizing new gestures, 221–222 Xcode, 7–8 iOS apps See also blueprint project files adding resources to, 24 common files for, 23–24 coordinate system for, 48–49 designing and developing, 5, 51 development strategies for, 11–18 folders in home directory, 21 full-screen, 28 Home button’s effect on, 44–45 Human Interface Guidelines for, 16–18 info.plist settings for, 26 localizing, 25 memory management for, 14–16 MVC architecture for, 12–13 performance when refreshing views, 55 Power/Lock button’s effect on, 45 productivity or navigation, 27–28 registering as developer for, 7, selecting project type for, 30–31 subclassing in, 13–14 testing, 11 types of, 26–28 user workflows for, 22, 45 utility, 27 views in, 53–54 iOS Developer Program, iOS devices See also physical hardware; and specific devices adding motion gestures for, 237–241 automatic rotation of, 47 camera sessions for, 42–43 choosing app’s product type for, 31 display resolutions and coordinate systems for, 49 folders backed up for, 22 HIDs for, 40–41 Multi-Touch display for, 41 multitasking for, 22 orientation of, 43–44, 46–47 preparing images for multiple, 49–50 selecting type for Xcode projects, 31–32 iOS SDK, 7, iOS Simulator, 7, 9–10 iPad action sheet display for, 92–93 controlling popover view, 83–85, 93 HID for, 41 modal presentation styles for, 87–88 multitasking for, 22 Mute switch for, 44 preparing images for, 49–50 supported device orientation for, 46 using split view, 81–83 iPhone clock app, 78–79 HID for, 40 iPhone OS, 5–6, 20 multitasking for, 22 Mute switch for, 44 pixels vs points for, 48–49 preparing images for, 49–50 Index retina display and custom buttons, 129 supported device orientation for, 46 view life cycle of iPod app, 75–76 iPod device orientation for iPod touch, 46 iOS versions for, 6–7 view life cycle of iPod app, 75–76 iTunes App Store app review guidelines for, submitting apps to, worldwide distribution from, 25 iTunes Connect, 119 K keyboard Multi-Touch display for, 41 styles of, 106, 108 keyframe animations, 191–195 L labels changing button, 127 using UILabel objects, 58–60 launch images, 120–122 libraries framework files for, 23 using Quartz, 189–190 loading screens, 64 localization files, 25 low-resolution image files, 49–50 M m (methods) files, 23–24 generating and editing AppDelegate, 32–33 required for UIView subclasses, 143 ScrollViewController, 217–218 setting up DetailViewController, 165–167 Mac OS X iOS vs., 20–23 Quartz 2D and, 144 memory management, 14–16, 55 messages for alert dialogs, 90–91 metaphors, 18 methods See also m files animated parameter for, 180 canBecomeFirstResponder, 239 configuring table view data source and delegate protocols, 150–152 creating custom subclasses, 163–164 drawRect, 55, 143–144, 156–157 implementing UITableView data source and delegate, 169–170 needed to track touch events, 223 recognizing shake, 239 touchesBegan, 223–225, 236, 242 touchesCancelled, 226–227, 242 touchesEnded, 226 touchesMoved, 225 UIButton class interface, 125 UIView animation, 178 UIWebView, 62–64 view life cycle, 75–76, 80, 239 modal view controllers, 85–88 about, 85–86 modal presentation styles, 87–88 modal transition styles, 86–87 Model component, 13 motion gestures 237–241 See also shake triggering shake gestures, 238–239 using accelerometer or gyroscope, 238 Multi-Touch display, 41 Multimedia Programming Guide, 42 multitasking with iOS, 22–23 Mute switch, 44 MVC (Model-View-Controller) architecture about, 12–13 UIView superclass and, 71 understanding UITableView with, 150 N naming classes consistently, 135 icons, 119 image files, 49–50 launch images, 121 tab bar images, 124 navigation designing navigation apps, 27–28 UINavigationController, 79–81, 183 UITabBarController, 77–79 UIViewController styles of, 76–77 nib (.xib) files, 23, 25, 74, 132 O Objective-C memory management, 14–16 operating system See iOS orientation See also rotation controlling iPad split view, 81–83 determining device’s, 46–47 handling automatic rotation, 47, 72 hardware detecting, 43–44 list of supported device, 46 P page controls, 94–95 panning customizing countdown timer for, 242–246 triggering recognition of, 233 using in UIScrollView, 214–215 paths, 145–146, 193–195 251 252 Index performance improving animation, 188–189 optimizing view refreshing, 55 reusing table cells, 155 Photoshop action scripts for, 120 editing images in, 118 physical hardware, 39–50 about, 39 accelerometer and gyroscope, 43–44, 238 apps for camera, 42–43 coordinate system, 48–49, 54 device orientation, 45–47 HIDs, 40 Home button, 44–45 Mute switch, 44 Power/Lock button, 45 preparing images for multiple displays, 49–50 volume controls, 43 pickers, 102–103 pinch open/pinch close about, 212 controlling zooming with, 216 gesture recognizers for, 230–231 pixels launch image size in, 121 points vs., 48–49 plist files configuring icon’s info, 120 defined, 24 settings controlled by, 26 points, 48–49 popover view, 83–85, 93 Power/Lock button, 45 press-and-hold gesture about touch and hold, 212–213 gesture recognizers for, 235–236 productivity apps, 27–28 programming allocating/deallocating variables from memory, 14–16 calling delegates, 63 controlling accelerometer, 44 editing “Hello, World!” in Xcode, 32–35 subclassing, 13–14 progress bar, 94–95 projects See also blueprint project files creating in Xcode, 31–32 including Quartz library in, 189–190 sample “Hello, World!,” 29–35 selecting type of, 30–31 properties adding to custom view controller, 135–138 cell, 154 modal presentation styles, 87–88 modal transition styles, 86–87 needed to track touch events, 223 setting for button title states, 100–101 setting table view appearance, 152–156 styles for action sheets, 93 UILabel, 58–59 UIPopoverController, 84 UIScrollView, 65–66 UIToolbar, 69 UIView animation, 174–175 UIWebView, 62 view frame and bounds, 56 push and pop navigation, 79–81, 183 Q Quartz 2D, 132, 144–145, 189–190 R reordering rows, 159–160 resources adding to iOS apps, 24 app, 24–25 defined, 24 development tool, 7–11 retina display custom buttons for, 129 designing apps for, 48–49 reuseIdentifier tag, 55 reusing cells, 155 views, 55, 236–237 rotation applying 3D transforms for, 196–198 handling automatic, 47, 72 triggering gesture recognizer, 231–233 Rounded Rectangle button, 100, 126–127 rows See also table views animation styles for, 182 implementing animated countdown timer for, 199–206 moving, deleting, and inserting rows, 158–161 S sample projects See blueprint project files scroll view calling indicators for, 216 code example for, 66–67 gesture properties for, 215 using UIScrollView, 214–215 zooming behaviors for, 216–219 segmented controls, 103–104 setEditing method, 161 setHidden method, 181 setNeedsDisplay function, 55 shake defined, 213 recognizing events using, 239–241 triggering, 238–239 Index single-finger drag, 210–211 single-finger tap, 210–211 sliders, 105 spinners, 94–95 split view, 81–83 states gesture recognizer, 228–229 setting for custom UIButtons, 125–129 setting properties for button title, 100–101 status bars, 181 subclasses about, 13–14 creating custom cells with UITableViewCell, 156–158 header/methods files for custom, 163–164 implementing custom UIGestureRecognizer, 237 subclassing custom UIViews, 57, 143–144 UITableViewController, 149–150 UIView objects vs., 57 using UIViewController as, 131 superclasses, UIView, 71 swipes, 161, 211, 234 switch, 104 system-provided animations, 180–183 about, 180 custom vs., 85 UIApplication’s, 181 UINavigationController’s, 183 UITableViewController’s, 182 UITableView’s, 182 UIViewController’s, 181 system-provided buttons, 97–100 T tab bar customizing images for, 123–124 modifying system-provided, 167–168 system-provided buttons for, 99 UITabBarController objects for, 77–79 table views, 149-170 See also cells; rows about, 149–150 cell accessory view styles, 155 creating custom cells, 156–158 data source and delegate for, 150–152 header and footer view, 155–156 managing cells in, 153–154 moving, deleting, and inserting rows, 158–161 reusing cells, 155 setting appearance properties for, 152–156 tabs adding UIControls to, 109–112 creating UIViewController for, 108–109 customizing, 162–170 253 tap gesture double, 212, 216 single-finger, 210–211 triggering UITapGestureRecognizer, 229–230 templates See blueprint project files testing iOS apps, 11 text changing properties of button label, 127 designing button, 100–101 designing fields for, 105–106 displaying with UILabel, 58–60 methods for drawing, 148 3D transforms, 196–198 time pickers, 102 titles alert dialogs, 90–91 setting properties for button states, 100–101 toolbars plain vs bordered button styles for, 97 spacing buttons on, 70 system-provided buttons for, 97–99 tools See also Interface Builder; Xcode Application Sandbox, 21–22 downloading iOS, Instruments, 7, 11 iOS Simulator, 7, 9–10 resources for development, 7–11 touch and hold about, 212–213 UILongPressGestureRecognizer for, 235–236 touch events cancelling, 226–227, 242 detecting end of, 226 gesture recognizers detecting, 227–229 methods and properties for, 223 moved, 225 Multi-Touch display and, 41 recognizing initial touch, 223–225 tracking in UIView, 222–227 using gesture recognizer vs touchesBegan to track, 236, 242 touchesBegan method, 223–225, 236, 242 touchesCancelled method, 226–227, 242 touchesEnded method, 226 touchesMoved method, 242 transitions defining keyframe animation, 192 types of animation, 195–196 U UIActionSheets, 90 UIActivityIndicatorViews, 94–95 UIAlertViews, 90–92 UIApplication system-provided animations, 181 UIBarButtonItem class, 124–125 254 Index UIButtons creating video thumbnails with, 128–129 customizing states for, 125–129 types of, 100–101 UIButtonTypeRoundedRect, 100–101 UIControlEventValueChanged, 104–105 UIControls about, 96 adding to tab, 109–111 creating UIViewController for, 108–109 UIButton options, 100–101 UIControlStates elements, 124–125 UIGestureRecognizers about, 227 implementing own subclass for, 237 types of predefined, 228 UILongPressGestureRecognizer, 235–236 UIPanGestureRecognizer, 233 UIPinchGestureRecognizer, 230–231 UIRotationGestureRecognizer, 231–232 UISwipeGestureRecognizer, 234 UITapGestureRecognizer, 229–230 UIImage and UIImageView objects, 60–61 UIKit, 57–69 about, 52, 57–58, 174–175 classes in, 58 Core Animation vs., 187–188 developing UIView animation blocks using, 175–177 3D card flip animation using, 196–198 transitioning between UIViews, 179–180 UIImage and UIImageView, 60–61 UILabel, 58–60 UIScrollView object, 65–67 UITableView and UITableViewCell objects, 68–69 UIToolbar object, 69–70 UIView object in, 53–54 UIWebView, 61–64 using gestures of, 213–214 UILabel, 58–60 UILongPressGestureRecognizer, 235–236 UINavigationController, 79–81, 183 UIPageControl, 95 UIPanGestureRecognizer, 233, 242–246 UIPicker class, 102–103 UIPinchGestureRecognizer, 230–231 UIPopoverController, 83–85, 93 UIProgressView, 95 UIResponder, 238 UIRotationGestureRecognizer, 231–232 UIScrollViews code example of, 66–67 gesture properties for, 215 properties and descriptions for, 65–66 scroll view indicators for, 216 using, 214–215 zooming behaviors for, 216–219 UISegmentedControl Styles, 103–104 UISlider, 105 UISplitViewController, 81–83 UISwipeGestureRecognizer, 234 UITabBarController, 114 UITabBarItem, 122–124, 167–168 UITableViewCells about, 68–69, 153–154 creating custom cells, 156–158 UITableViewControllers data source and delegate protocols for, 150–152 setting appearance properties for, 152–156 system-provided animations for, 182 understanding with MVC model, 150 working with, 149–150 UITableViewDataSource protocol, 150–151 UITableViewDelegateprotocol, 151–152 UITableViews about, 68–69 implementing data source and delegate for, 169–170 moving, deleting, and inserting rows, 158–161 scroll view indicators for, 216 system-provided animations for, 182 UITableViewStyle, 152–153 UITapGestureRecognizer, 229–230 UITextField, 105–106 UIToolbar, 69–70 UITouch, 222 UIViewControllers, 132–142 about, 72–73, 131 adding properties to, 135–138 building custom interface, 138–140 creating, 107–114 custom UIViews vs., 142 implementing CountdownViewController, 199–200 including in custom interface, 140–142 managing views with, 73–75 multiple view controllers, 72, 75 navigation styles for, 76–77 system-provided animations for, 181 UITabBarController, 77–79 UITableViewController subclass of, 149–150 view life cycle methods, 75–76 UIViews, 142–148 about, 53–54 animation methods for, 178 animation properties in, 174–175 custom UIViewControllers vs., 142 customizing, 131, 142–143 designing loading screens, 64 Index developing animation blocks in, 175–177 drawing paths for, 145–146 drawing text for, 148 example of, 56–57 gesture recognizers for, 221–222 subclasses for, 57, 143–144 table view header and footer for, 155–156 tracking touches in, 222–227 transform functions for, 146 transitioning between, 179–180 UIControl subclass of, 96 UIViews superclass and MVC architecture, 71 using blend modes for images, 147–148 UIWebViewDelegate protocol, 63 UIWebViews, 61–64 UIWindow object, 53–54 user experience (UX) animation and, 179 app workflows and, 22, 45 importance of, physical hardware and, 39 reordering rows in table view, 159–160 user interface See also buttons; physical hardware; view controllers; views alternatives for gestures in, 214 Apple guidelines for, 16–18 blueprint for customizing, 162–170 building custom, 138–140 commonly used objects for, 57–69 design and user experience, designing and developing apps for, 51 developing icons, 118 importance of custom UIViews, 142–143 indicators, 94–95 loading screens, 64 localizing, 25 managing view hierarchy, 46–47, 54–55 pickers, 102–103 refreshing views, 55 segmented controls, 103–104 selecting device type for Xcode projects, 31–32 sliders, 105 subclassing in, 13–14 switches, 104 text fields, 105–106 types of apps, 26–28 user control of apps, 18 using MVC architecture for, 12–13 utilities, 27 V variables, 14–16 video custom video thumbnail buttons, 128–129 file types supported, 24–25 255 view controllers about, 72–73 accessing orientation of, 46–47 connecting controls to, 112–113 creating custom UIViewControllers, 132–142 handling device rotation, 47, 72 modal view, 85–88 multiple, 72, 75 MVC model and Controller component, 12–13 pushing onto navigation stack, 79–81 recognizing shake events, 239 system-provided animations for, 181 UIPopoverController, 83–85, 93 UISplitViewController, 81–83 view hierarchy, 46–47, 54–55 view life cycle methods, 75–76, 80, 239 viewDidAppear method, 239 viewDidLoad method, 167 views See also table views about, 53–54 alert dialogs and action sheets, 90 coordinate system for, 48–49, 54 embedding views within, 65 frame and bounds properties for, 56 hierarchy of, 46–47, 54–55 modal, 85–86 multiple gesture recognizers for, 228–229 MVC model and, 12–13, 71 popover, 83–85, 93 progress view, 95 refreshing, 55 reusing, 55, 236–237 split, 81–83 transforming with rotate gesture, 231–232 UIView example, 56–57 view life cycle methods, 75–76, 80, 239 volume, 43–44 X Xcode See also Interface Builder about, 7–8 building application in, 137–138 creating sample project in, 29–35 customizing UIViewControllers in, 132–138 downloading, editing “Hello, World!” in Xcode, 32–35 illustrated, 29–30 including Quartz library in projects, 189–190 selecting project type in, 30–31 using files in Interface Builder, 138–140 xib (Interface Builder) files, 23, 25, 74, 132 Z zooming behavior, 212, 216–219 WATCH READ CREATE Meet Creative Edge A new resource of unlimited books, videos and tutorials for creatives from the world’s leading experts Creative Edge is your one stop for inspiration, answers to technical questions and ways to stay at the top of your game so you can focus on what you best—being creative All for only $24.99 per month for access—any day any time you need it peachpit.com/creativeedge

Ngày đăng: 18/01/2018, 12:57

Mục lục

  • Table of Contents

  • Part I: Introduction

    • 1. Getting Started with iOS

      • Why Are We Here?

      • iOS Devices

      • iOS Development Tools and Resources

      • Quick Tips: iOS Development Strategies

      • Guiding Principles

    • 2. What Makes an iOS App?

      • iOS: The Big Picture

      • Application Types

      • iOS App Blueprint: Introduction and “Hello, World!”

      • Creating an Xcode Project

      • Conclusion

  • Part II: the Basics of iOS User Interfaces

    • 3. Physical Hardware

      • Physical Input Devices

      • Device Orientation

      • iOS Coordinate System

      • Preparing Image Assets for Multiple Displays

    • 4. Basic User Interface Objects

      • UIKit and Foundation

      • iOS Views

      • UIKit

    • 5. User Interface Controllers and Navigation

      • What Is a Controller?

      • View Controllers, Navigation, and Modal Views

    • 6. User Interface Buttons, Inputs, Indicators, and Controls

      • Alert Dialogs and Action Sheets

      • Indicators

      • Controls and Buttons

      • iOS App Blueprint: The Basics

      • Creating UIViewControllers

      • Adding UIControls to Each Tab

      • Connecting UI Controls to a Controller

      • Create a UITabBarController

  • Part III: Designing Custom iOS User Interface Objects

    • 7. Creating Custom Icons, Launch Images, and Buttons

      • App Icons

      • Launch Images

      • Custom UI Buttons

    • 8. Creating Custom UIViews and UIViewControllers

      • Custom UIViewControllers

      • Custom UIViews

    • 9. Creating Custom Table Views

      • UITableViewController

      • UITableView Appearance

      • Creating Custom Cells

      • Moving, Deleting, and Inserting Rows

      • iOS App Blueprint: Custom iOS UI

      • Overview

      • Changes to the First Tab

  • Part IV: animating Your UI

    • 10. Introduction to iOS Animations

      • About Animations Using UIKit

      • UIView Animation Blocks

      • System-Provided Animations

    • 11. Creating Custom iOS Animations

      • About Core Animation

      • Core Animation Types

      • Getting Started with Core Animations

      • Keyframe Animations

      • Animation Transitions

      • 3D Transforms

      • iOS App Blueprint: Custom Animations

      • Overview

      • Animations of CountdownViewController

  • Part V: Human Interaction: Gestures

    • 12. Introduction to iOS Gestures

      • Understanding Apple-Defined Gestures

      • Gestures and UIKit

    • 13. Creating Custom iOS Gestures

      • Detecting Touches in a UIView

      • Gesture Recognizers

      • Motion Gestures

      • iOS App Blueprint: Custom Gestures

      • Overview

      • Note from the Author

  • Index

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    • I

    • K

    • L

    • M

    • N

    • O

    • P

    • Q

    • R

    • S

    • T

    • U

    • V

    • X

    • Z

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan