You are previewing Programming iOS 10.
O'Reilly logo
Programming iOS 10

Book Description

If you’re grounded in the basics of Swift, Xcode, and the Cocoa framework, this book provides a structured explanation of all essential real-world iOS app components. Through deep exploration and copious code examples, you’ll learn how to create views, manipulate view controllers, and add features from iOS frameworks.

Table of Contents

  1. Preface
    1. The Scope of This Book
    2. Versions
    3. Acknowledgments
    4. From the Programming iOS 4 Preface
    5. Conventions Used in This Book
    6. Using Code Examples
    7. O’Reilly Safari
    8. How to Contact Us
  2. I. Views
    1. 1. Views
      1. The Window
      2. Experimenting with Views
      3. Subview and Superview
      4. Visibility and Opacity
      5. Frame
      6. Bounds and Center
      7. Window Coordinates and Screen Coordinates
      8. Transform
      9. App Rotation
      10. Trait Collections and Size Classes
      11. Layout
        1. Autoresizing
        2. Autolayout
        3. Constraints
        4. Autoresizing Constraints
        5. Creating Constraints in Code
        6. Constraints as Objects
        7. Guides and Margins
        8. Intrinsic Content Size and Alignment Rects
        9. Stack Views
        10. Internationalization
        11. Mistakes with Constraints
      12. Configuring Layout in the Nib
        1. Autoresizing in the Nib
        2. Creating a Constraint
        3. Viewing and Editing Constraints
        4. Problems with Constraints
        5. Varying the Screen Size
        6. Conditional Interface Design
      13. Nib Editor View Features
        1. View Debugger
        2. Previewing Your Interface
        3. Designable Views and Inspectable Properties
      14. Layout Events
    2. 2. Drawing
      1. Images and Image Views
        1. Image Files
        2. Image Views
        3. Resizable Images
        4. Transparency Masks
        5. Reversible Images
      2. Graphics Contexts
      3. UIImage Drawing
      4. CGImage Drawing
      5. Snapshots
      6. CIFilter and CIImage
      7. Blur and Vibrancy Views
      8. Drawing a UIView
      9. Graphics Context Commands
        1. Graphics Context Settings
        2. Paths and Shapes
        3. Clipping
        4. Gradients
        5. Colors and Patterns
        6. Graphics Context Transforms
        7. Shadows
        8. Erasing
      10. Points and Pixels
      11. Content Mode
    3. 3. Layers
      1. View and Layer
      2. Layers and Sublayers
        1. Manipulating the Layer Hierarchy
        2. Positioning a Sublayer
        3. CAScrollLayer
        4. Layout of Sublayers
      3. Drawing in a Layer
        1. Content Resizing and Positioning
        2. Layers that Draw Themselves
      4. Transforms
        1. Depth
      5. Shadows, Borders, and Masks
      6. Layer Efficiency
      7. Layers and Key–Value Coding
    4. 4. Animation
      1. Drawing, Animation, and Threading
      2. Image View and Image Animation
      3. View Animation
        1. A Brief History of View Animation
        2. Property Animator Basics
        3. View Animation Basics
        4. View Animation Configuration
        5. Timing Curves
        6. Canceling a View Animation
        7. Frozen View Animation
        8. Custom Animatable View Properties
        9. Keyframe View Animation
        10. Transitions
      4. Implicit Layer Animation
        1. Animation Transactions
        2. Media Timing Functions
      5. Core Animation
        1. CABasicAnimation and Its Inheritance
        2. Using a CABasicAnimation
        3. Springing Animation
        4. Keyframe Animation
        5. Making a Property Animatable
        6. Grouped Animations
        7. Freezing an Animation
        8. Transitions
        9. Animations List
      6. Actions
        1. What an Action Is
        2. Action Search
        3. Hooking Into the Action Search
        4. Making a Custom Property Implicitly Animatable
        5. Nonproperty Actions
      7. Emitter Layers
      8. CIFilter Transitions
      9. UIKit Dynamics
        1. The Dynamics Stack
        2. Custom Behaviors
        3. Animator and Behaviors
      10. Motion Effects
      11. Animation and Autolayout
    5. 5. Touches
      1. Touch Events and Views
      2. Receiving Touches
      3. Restricting Touches
      4. Interpreting Touches
      5. Gesture Recognizers
        1. Gesture Recognizer Classes
        2. Gesture Recognizer Conflicts
        3. Subclassing Gesture Recognizers
        4. Gesture Recognizer Delegate
        5. Gesture Recognizers in the Nib
      6. 3D Touch Press Gesture
      7. Touch Delivery
      8. Hit-Testing
        1. Performing Hit-Testing
        2. Hit-Test Munging
        3. Hit-Testing For Layers
        4. Hit-Testing For Drawings
        5. Hit-Testing During Animation
      9. Initial Touch Event Delivery
      10. Gesture Recognizer and View
      11. Touch Exclusion Logic
      12. Gesture Recognition Logic
      13. Touches and the Responder Chain
  3. II. Interface
    1. 6. View Controllers
      1. View Controller Responsibilities
      2. View Controller Hierarchy
      3. View Controller Creation
      4. How a View Controller Obtains Its View
        1. Manual View
        2. Generic Automatic View
        3. View in a Separate Nib
        4. Summary
      5. How Storyboards Work
        1. How a View Controller Nib is Loaded
        2. How a View Nib is Loaded
      6. View Resizing
        1. View Size in the Nib Editor
        2. Bars and Underlapping
        3. Resizing Events
        4. Rotation
      7. View Controller Manual Layout
      8. Presented View Controller
        1. Presentation and Dismissal
        2. Configuring a Presentation
        3. Communication with a Presented View Controller
        4. Adaptive Presentation
        5. Presentation and Rotation
      9. Tab Bar Controller
        1. Tab Bar Items
        2. Configuring a Tab Bar Controller
      10. Navigation Controller
        1. Bar Button Items
        2. Navigation Items and Toolbar Items
        3. Configuring a Navigation Controller
      11. Custom Transition
        1. Noninteractive Custom Transition Animation
        2. Interactive Custom Transition Animation
        3. Interruptible Custom Transition Animation
        4. Custom Presented View Controller Transition
        5. Transition Coordinator
      12. Page View Controller
        1. Preparing a Page View Controller
        2. Page View Controller Navigation
        3. Other Page View Controller Configurations
      13. Container View Controllers
        1. Adding and Removing Children
        2. Container View Controllers, Traits, and Resizing
      14. Peek and Pop
      15. Storyboards
        1. Triggered Segues
        2. Container Views and Embed Segues
        3. Storyboard References
        4. Unwind Segues
      16. View Controller Lifetime Events
        1. Incoherencies in View Controller Events
        2. Appear and Disappear Events
        3. Event Forwarding to a Child View Controller
      17. View Controller Memory Management
      18. State Restoration
        1. How to Test State Restoration
        2. Participating in State Restoration
        3. Restoration ID, Identifier Path, and Restoration Class
        4. Restoring View Controller State
        5. Restoration Order of Operations
        6. Restoration of Other Objects
        7. Snapshot Suppression
    2. 7. Scroll Views
      1. Creating a Scroll View in Code
        1. Manual Content Size
        2. Automatic Content Size with Autolayout
        3. Using a Content View
      2. Scroll View in a Nib
      3. Scrolling
        1. Paging
        2. Tiling
      4. Zooming
        1. Zooming Programmatically
        2. Zooming with Detail
      5. Scroll View Delegate
      6. Scroll View Touches
      7. Floating Scroll View Subviews
      8. Scroll View Performance
    3. 8. Table Views and Collection Views
      1. Table View Cells
        1. Built-In Cell Styles
        2. Registering a Cell Class
        3. Custom Cells
      2. Table View Data
        1. The Three Big Questions
        2. Reusing Cells
      3. Table View Sections
        1. Section Headers and Footers
        2. Section Data
        3. Section Index
      4. Refreshing a Table View
        1. Direct Access to Cells
        2. Refresh Control
      5. Variable Row Heights
        1. Manual Row Height Measurement
        2. Measurement and Layout with Constraints
        3. Estimated Height
        4. Automatic Row Height
      6. Table View Cell Selection
        1. Managing Cell Selection
        2. Responding to Cell Selection
        3. Navigation from a Table View
        4. Cell Choice and Static Tables
      7. Table View Scrolling and Layout
      8. Table View State Restoration
      9. Table View Searching
        1. Configuring a Search Controller
        2. Using a Search Controller
      10. Table View Editing
        1. Deleting Cells
        2. Custom Action Buttons
        3. Editable Content in Cells
        4. Inserting Cells
        5. Rearranging Cells
        6. Dynamic Cells
      11. Table View Menus
      12. Collection Views
      13. Collection View Classes
      14. Using a Collection View
        1. Deleting Cells
        2. Rearranging Cells
      15. Custom Collection View Layouts
        1. UICollectionViewFlowLayout Subclass
        2. UICollectionViewLayout Subclass
        3. Decoration Views
      16. Switching Layouts
      17. Collection Views and UIKit Dynamics
    4. 9. iPad Interface
      1. Popovers
        1. Arrow Source and Direction
        2. Popover Size and Position
        3. Popover Appearance
        4. Passthrough Views
        5. Popover Presentation, Dismissal, and Delegate
        6. Adaptive Popovers
        7. Popover Segues
        8. Popover Presenting a View Controller
      2. Split Views
        1. Expanded Split View Controller (iPad)
        2. Collapsed Split View Controller (iPhone)
        3. Expanding Split View Controller (iPhone 6 Plus)
        4. Customizing a Split View Controller
        5. Split View Controller in a Storyboard
        6. Setting the Collapsed State
        7. View Controller Message Percolation
      3. iPad Multitasking
    5. 10. Text
      1. Fonts and Font Descriptors
        1. Fonts
        2. Font Descriptors
      2. Attributed Strings
        1. Attributed String Attributes
        2. Making an Attributed String
        3. Modifying and Querying an Attributed String
        4. Custom Attributes
        5. Drawing and Measuring an Attributed String
      3. Labels
        1. Number of Lines
        2. Wrapping and Truncation
        3. Resizing a Label to Fit Its Text
        4. Customized Label Drawing
      4. Text Fields
        1. Summoning and Dismissing the Keyboard
        2. Keyboard Covers Text Field
        3. Configuring the Keyboard
        4. Text Field Delegate and Control Event Messages
        5. Text Field Menu
      5. Text Views
        1. Text View as Scroll View
        2. Text View and Keyboard
      6. Text Kit
        1. Text Container
        2. Alternative Text Kit Stack Architectures
        3. Layout Manager
        4. Text Kit Without a Text View
    6. 11. Web Views
      1. WKWebView
        1. Web View Content
        2. Tracking Changes in a Web View
        3. Web View Navigation
        4. Communicating with a Web Page
        5. WKWebView Shortcomings
      2. Safari View Controller
      3. Developing Web View Content
    7. 12. Controls and Other Views
      1. UIActivityIndicatorView
      2. UIProgressView
      3. UIPickerView
      4. UISearchBar
      5. UIControl
        1. UISwitch
        2. UIStepper
        3. UIPageControl
        4. UIDatePicker
        5. UISlider
        6. UISegmentedControl
        7. UIButton
        8. Custom Controls
      6. Bars
        1. Bar Position and Bar Metrics
        2. Bar Appearance
        3. UIBarButtonItem
        4. UINavigationBar
        5. UIToolbar
        6. UITabBar
      7. Tint Color
      8. Appearance Proxy
    8. 13. Modal Dialogs
      1. Alerts and Action Sheets
        1. Alerts
        2. Action Sheets
        3. Dialog Alternatives
      2. Quick Actions
      3. Local Notifications
        1. Authorizing for Local Notifications
        2. Notification Category
        3. Scheduling a Local Notification
        4. Hearing About a Local Notification
        5. Managing Scheduled Notifications
        6. Notification Content Extensions
      4. Today Extensions
      5. Activity Views
        1. Presenting an Activity View
        2. Custom Activities
        3. Action Extensions
        4. Share Extensions
  4. III. Some Frameworks
    1. 14. Audio
      1. System Sounds
      2. Audio Session
        1. Activation
        2. Ducking
        3. Interruptions
        4. Secondary Audio
        5. Routing Changes
      3. Audio Player
      4. Remote Control of Your Sound
      5. Playing Sound in the Background
      6. AVAudioEngine
      7. MIDI Playback
      8. Text to Speech
      9. Speech to Text
      10. Further Topics in Sound
    2. 15. Video
      1. AVPlayerViewController
        1. Other AVPlayerViewController Properties
        2. Picture-in-Picture
      2. Introducing AV Foundation
        1. Some AV Foundation Classes
        2. Things Take Time
        3. Time is Measured Oddly
        4. Constructing Media
        5. Synchronizing Animation with Video
        6. AVPlayerLayer
        7. Further Exploration of AV Foundation
      3. UIVideoEditorController
    3. 16. Music Library
      1. Music Library Authorization
      2. Exploring the Music Library
        1. Querying the Music Library
        2. Persistence and Change in the Music Library
      3. Music Player
      4. MPVolumeView
      5. Playing Songs with AV Foundation
      6. Media Picker
    4. 17. Photo Library and Camera
      1. Browsing with UIImagePickerController
      2. Photos Framework
        1. Querying the Photo Library
        2. Modifying the Library
        3. Being Notified of Changes
        4. Displaying Images
        5. Editing Images
        6. Photo Editing Extension
      3. Using the Camera
        1. Capture with UIImagePickerController
        2. Capture with AV Foundation
    5. 18. Contacts
      1. Contact Classes
      2. Fetching Contact Information
      3. Saving Contact Information
      4. Contact Sorting, Groups, and Containers
      5. Contacts Interface
        1. CNContactPickerViewController
        2. CNContactViewController
    6. 19. Calendar
      1. Calendar Database Contents
        1. Calendars
        2. Calendar Items
      2. Calendar Database Changes
      3. Creating Calendars and Events
      4. Recurrence
      5. Fetching Events
      6. Reminders
      7. Proximity Alarms
      8. Calendar Interface
        1. EKEventViewController
        2. EKEventEditViewController
        3. EKCalendarChooser
    7. 20. Maps
      1. Displaying a Map
      2. Annotations
        1. Custom Annotation View
        2. Custom Annotation Class
        3. Other Annotation Features
      3. Overlays
        1. Custom Overlay Class
        2. Custom Overlay Renderer
        3. Other Overlay Features
      4. Map Kit and Current Location
      5. Communicating with the Maps App
      6. Geocoding, Searching, and Directions
        1. Geocoding
        2. Searching
        3. Directions
    8. 21. Sensors
      1. Core Location
        1. Location Manager, Delegate, and Authorization
        2. Location Tracking
        3. Where Am I?
        4. Background Location
        5. Heading
      2. Acceleration, Attitude, and Activity
        1. Shake Events
        2. Raw Acceleration
        3. Gyroscope
        4. Motion Activity
  5. IV. Final Topics
    1. 22. Persistent Storage
      1. The Sandbox
        1. Standard Directories
        2. Visually Inspecting the Sandbox
        3. Basic File Operations
        4. Saving and Reading Files
      2. User Defaults
      3. Simple Sharing and Previewing of Files
        1. File Sharing
        2. Document Types and Receiving a Document
        3. Handing Over a Document
        4. Previewing a Document
      4. Document Architecture
      5. iCloud
      6. XML
      7. SQLite
      8. Core Data
      9. Image File Formats
    2. 23. Basic Networking
      1. HTTP Requests
        1. Simple HTTP Request
        2. Formal HTTP Request
        3. Encapsulating the Session and Delegate
        4. Downloading Table View Data
        5. Background Downloads
        6. Background App Refresh
      2. On-Demand Resources
      3. In-App Purchases
    3. 24. Threads
      1. Main Thread
      2. Why Threading Is Hard
      3. Blocking the Main Thread
      4. Manual Threading
      5. Operation
      6. Grand Central Dispatch
      7. Threads and App Backgrounding
    4. 25. Undo
      1. Undo Manager
        1. Target–Action Undo
        2. Undo Grouping
        3. Functional Undo
      2. Undo Interface
        1. Shake-To-Edit
        2. Undo Menu
    5. A. Application Lifetime Events
      1. Application States
      2. App Delegate Events
      3. App Lifetime Scenarios
    6. B. Some Useful Utility Functions
      1. Launch Without Main Storyboard
      2. Core Graphics Initializers
      3. Center of a CGRect
      4. Adjust a CGSize
      5. Delayed Performance
      6. Dictionary of Views
      7. Constraint Issues
      8. Configure a Value Class at Point of Use
      9. Drawing Into an Image Context
      10. Finite Repetition of an Animation
      11. Remove Multiple Indexes From Array
    7. C. How Asynchronous Works
  6. Index