ebook img

Programming iOS 14: Dive Deep into Views, View Controllers, and Frameworks PDF

1259 Pages·2020·13.16 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Programming iOS 14: Dive Deep into Views, View Controllers, and Frameworks

X c o C d o e v 1 er 2, s i a Programming nOS d 1 S 4 , wi f t 5. 3 iOS 14 Dive Deep into Views, View Controllers, and Frameworks Matt Neuburg ELEVENTH EDITION Programming iOS 14 Dive Deep into Views, View Controllers, and Frameworks Matt Neuburg Boston Programming iOS 14, Eleventh Edition by Matt Neuburg Copyright © 2021 Matt Neuburg. All rights reserved. Printed in Canada. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institu‐ tional sales department: 800-998-9938 or [email protected]. Editors: Rachel Roumeliotis and Suzanne McQuade Indexer: Matt Neuburg Production Editor: Kristen Brown Cover Designer: Karen Montgomery Proofreader: O’Reilly Production Services Interior Designer: David Futato Illustrator: Matt Neuburg November 2015: Sixth Edition November 2016: Seventh Edition December 2017: Eighth Edition October 2018: Ninth Edition October 2019: Tenth Edition October 2020: Eleventh Edition Revision History for the Eleventh Edition: 2020-10-08: First release See http://oreilly.com/catalog/errata.csp?isbn=9781492092179 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Programming iOS 14, the cover image of a kingbird, and related trade dress are trademarks of O’Reilly Media, Inc. 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 O’Reilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. 978-1-492-09217-9 [MBP] Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Part I. Views 1. Views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Window and Root View 4 Window Scene Architecture 4 How an App Launches 6 App Without a Storyboard 7 Referring to the Window 8 Experimenting with Views 9 Subview and Superview 10 Color 13 Visibility and Opacity 14 Frame 15 Bounds and Center 17 Transform 21 Transform3D 25 Window Coordinates and Screen Coordinates 27 Trait Collections 28 Interface Style 29 Size Classes 31 Overriding Trait Collections 32 Layout 32 Autoresizing 34 Autolayout and Constraints 36 Implicit Autoresizing Constraints 39 Creating Constraints in Code 40 Constraints as Objects 46 iii Margins and Guides 48 Intrinsic Content Size 54 Self-Sizing Views 56 Stack Views 57 Internationalization 60 Mistakes with Constraints 61 Configuring Layout in the Nib 64 Autoresizing in the Nib 65 Creating a Constraint 65 Viewing and Editing Constraints 67 Problems with Nib Constraints 69 Varying the Screen Size 71 Conditional Interface Design 72 Xcode View Features 75 View Debugger 75 Previewing Your Interface 76 Designable Views and Inspectable Properties 76 Layout Events 79 2. Drawing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Images and Image Views 81 Image Files 82 Image Views 88 Resizable Images 90 Transparency Masks 93 Reversible Images 95 Graphics Contexts 96 Drawing on Demand 98 Drawing a UIImage 99 UIImage Drawing 100 CGImage Drawing 103 Snapshots 105 CIFilter and CIImage 106 Blur and Vibrancy Views 111 Drawing a UIView 113 Graphics Context Commands 115 Graphics Context Settings 115 Paths and Shapes 116 Clipping 120 Gradients 121 Colors and Patterns 123 Graphics Context Transforms 125 iv | Table of Contents Shadows 127 Erasing 128 Points and Pixels 129 Content Mode 130 3. Layers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 View and Layer 134 Layers and Sublayers 135 Manipulating the Layer Hierarchy 138 Positioning a Sublayer 139 CAScrollLayer 140 Layer and Delegate 141 Layout of Layers 141 Drawing in a Layer 142 Drawing-Related Layer Properties 144 Content Resizing and Positioning 145 Layers that Draw Themselves 148 Transforms 148 Affine Transforms 149 3D Transforms 151 Depth 151 Further Layer Features 155 Shadows 155 Borders and Rounded Corners 156 Masks 157 Layer Efficiency 158 Layers and Key–Value Coding 159 4. Animation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Drawing, Animation, and Threading 164 Image View and Image Animation 166 View Animation 168 A Brief History of View Animation 168 Property Animator Basics 169 View Animation Basics 172 View Animation Configuration 175 Timing Curves 180 Cancelling a View Animation 183 Frozen View Animation 186 Custom Animatable View Properties 187 Keyframe View Animation 188 Transitions 191 Table of Contents | v Implicit Layer Animation 194 Animatable Layer Properties 194 Animating a Custom Layer Subclass 195 Animation Transactions 196 Media Timing Functions 198 Core Animation 198 CABasicAnimation and Its Inheritance 199 Using a CABasicAnimation 201 Springing Animation 204 Keyframe Animation 204 Making a Property Animatable 206 Grouped Animations 207 Animating Multiple Layers 211 Freezing an Animation 212 Transitions 213 Animations List 214 Actions 216 What an Action Is 217 Action Search 217 Hooking Into the Action Search 219 Making a Custom Property Implicitly Animatable 222 Nonproperty Actions 223 Emitter Layers 224 CIFilter Transitions 230 UIKit Dynamics 232 The Dynamics Stack 232 Custom Behaviors 236 Animator and Behaviors 238 Motion Effects 245 Animation and Layout 246 5. Touches. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 Touch Events and Views 250 Receiving Touches 252 Restricting Touches 254 Interpreting Touches 255 Gesture Recognizers 259 Gesture Recognizer Classes 260 Gesture Recognizer States 263 Gesture Recognizer Examples 263 Gesture Recognizer Conflicts 266 Gesture Recognizer Delegate 268 vi | Table of Contents Subclassing Gesture Recognizers 270 Gesture Recognizers in the Nib 273 Touch Delivery 273 Hit-Testing 274 Performing Hit-Testing 275 Hit-Test Munging 276 Hit-Testing for Layers 277 Hit-Testing for Drawings 278 Hit-Testing During Animation 279 Initial Touch Event Delivery 281 Gesture Recognizer and View 282 Touch Exclusion Logic 283 Gesture Recognition Logic 284 Part II. Interface 6. View Controllers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 View Controller Responsibilities 290 View Controller Hierarchy 291 Automatic Child View Placement 294 Manual Child View Placement 295 Presented View Placement 297 Ensuring a Coherent Hierarchy 299 View Controller Creation 300 How a View Controller Obtains Its View 301 Manual View 303 Generic Automatic View 304 View in a Separate Nib 305 Summary 308 How Storyboards Work 308 How a Storyboard View Controller Nib is Loaded 309 How a Storyboard View Nib is Loaded 311 View Resizing 311 View Size in the Nib Editor 312 Bars and Underlapping 312 Resizing and Layout Events 316 Rotation 318 Uses of Rotation 318 Permitting Compensatory Rotation 319 Initial Orientation 321 Detecting Rotation 321 Table of Contents | vii View Controller Manual Layout 322 Initial Manual Layout 322 Manual Layout During Rotation 323 Presented View Controller 325 Presentation and Dismissal 325 Configuring a Presentation 328 Communication with a Presented View Controller 334 Adaptive Presentation 336 Presentation, Rotation, and the Status Bar 338 Tab Bar Controller 339 Tab Bar Items 339 Configuring a Tab Bar Controller 341 Navigation Controller 343 Bar Button Items 345 Navigation Items and Toolbar Items 347 Configuring a Navigation Controller 350 Custom Transition 354 Noninteractive Custom Transition Animation 355 Interactive Custom Transition Animation 360 Custom Presented View Controller Transition 365 Transition Coordinator 371 Page View Controller 372 Preparing a Page View Controller 373 Page View Controller Navigation 375 Other Page View Controller Configurations 378 Container View Controllers 379 Adding and Removing Children 380 Status Bar, Traits, and Resizing 384 Previews and Context Menus 386 Context Menu Interaction and Configuration 386 Configuring the Preview 388 Configuring the Menu 390 Storyboards 391 Triggered Segues 396 Container Views and Embed Segues 401 Storyboard References 402 Unwind Segues 403 View Controller Lifetime Events 407 Order of Events 409 Appear and Disappear Events 410 Event Forwarding to a Child View Controller 410 View Controller Memory Management 412 viii | Table of Contents

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.