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

Book Description

Start building apps for iOS 8 with Apple’s Swift programming language. If you’re grounded in the basics of 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 use iOS frameworks for adding features such as audio and video, access to user calendars and photos, and tracking the device’s location.

Table of Contents

  1. Preface
    1. Versions
    2. Acknowledgments
    3. From the Programming iOS 4 Preface
    4. Conventions Used in This Book
    5. Using Code Examples
    6. Safari® Books Online
    7. 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. Trait Collections and Size Classes
      10. Layout
        1. Autoresizing
        2. Autolayout
          1. Constraints
          2. Autoresizing constraints
          3. Creating constraints in code
          4. Visual format
          5. Constraints as objects
          6. Guides and margins
          7. Mistakes with constraints
          8. Intrinsic content size
        3. Configuring Layout in the Nib
          1. Autoresizing in the nib
          2. Constraints in the nib
          3. Creating a constraint
          4. Viewing and editing constraints
          5. Problems with constraints
          6. Conditional constraints
        4. View Debugging, Previewing, and Designing
          1. View debugger
          2. Previewing your interface
          3. Resizable simulator
          4. Designable views and inspectable properties
        5. Events Related to Layout
    2. 2. Drawing
      1. UIImage
      2. UIImageView
        1. Resizable Images
        2. Image Rendering Mode
      3. Graphics Contexts
      4. UIImage Drawing
      5. CGImage Drawing
      6. Snapshots
      7. CIFilter and CIImage
      8. Blur and Vibrancy Views
      9. Drawing a UIView
      10. Graphics Context Settings
      11. Paths and Shapes
      12. Clipping
      13. Gradients
      14. Colors and Patterns
      15. Graphics Context Transforms
      16. Shadows
      17. Erasing
      18. Points and Pixels
      19. 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. UIImageView and UIImage Animation
      3. View Animation
        1. View Animation Options
        2. Canceling a View Animation
        3. Custom Animatable View Properties
        4. Springing View Animation
        5. Keyframe View Animation
        6. 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. Keyframe Animation
        4. Making a Property Animatable
        5. Grouped Animations
        6. Freezing an Animation
        7. Transitions
        8. 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
      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. Touch Delivery
        1. Hit-Testing
          1. Hit-testing for layers
          2. Hit-testing for drawings
          3. Hit-testing during animation
        2. Initial Touch Event Delivery
        3. Gesture Recognizer and View
        4. Touch Exclusion Logic
        5. Gesture Recognition Logic
        6. 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 Gets Its View
        1. Manual View
        2. Generic Automatic View
        3. View in a Separate Nib
        4. Nib-Instantiated View Controller
        5. Storyboard-Instantiated View Controller
      5. View Resizing
        1. View Size in the Nib Editor
        2. Bars and Underlapping
          1. Status bar visibility
          2. Extended layout
        3. Resizing Events
        4. Rotation
          1. Permitting compensatory rotation
          2. Initial orientation
          3. Initial layout
          4. Responding to rotation
      6. Presented View Controller
        1. Presenting a View
        2. Communication With a Presented View Controller
        3. Presented View Animation
        4. Presentation Styles
        5. Adaptive Presentation
        6. Rotation of a Presented View
      7. Tab Bar Controller
        1. Tab Bar Items
        2. Configuring a Tab Bar Controller
      8. Navigation Controller
        1. Bar Button Items
        2. Navigation Items and Toolbar Items
        3. Configuring a Navigation Controller
      9. Custom Transition
        1. Noninteractive Custom Transition Animation
        2. Interactive Custom Transition Animation
          1. Using a percent driver
          2. Without a percent driver
        3. Custom Presented View Controller Transition
          1. Customizing the animation
          2. Customizing the presentation
        4. Transition Coordinator
      10. Page View Controller
        1. Preparing a Page View Controller
        2. Page View Controller Navigation
          1. Page indicator
          2. Navigation gestures
        3. Other Page View Controller Configurations
      11. Container View Controllers
        1. Adding and Removing Children
        2. Container View Controllers, Traits, and Resizing
      12. Storyboards
        1. Segues
        2. Container Views
        3. Unwind Segues
      13. View Controller Lifetime Events
        1. Incoherencies in View Controller Events
        2. Appear and Disappear Events
        3. Event Forwarding to a Child View Controller
      14. View Controller Memory Management
      15. 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
          1. Overriding a cell’s subview layout
          2. Adding subviews in code
          3. Designing a cell in a nib
          4. Designing a cell in a storyboard
      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 Table View Data
        5. Variable Row Heights
          1. Manual row height measurement
          2. Measurement and layout with constraints
          3. Estimated height
          4. Automatic row height
      3. 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
      4. Table View Scrolling and Layout
      5. Table View State Restoration
      6. Table View Searching
        1. Configuring a Search Controller
        2. Using a Search Controller
          1. Minimal search results table
          2. Search bar scope buttons
          3. Customizing the presentation
          4. No secondary search results view controller
      7. Table View Editing
        1. Deleting Cells
        2. Custom Action Buttons
        3. Editable Content in Cells
        4. Inserting Cells
        5. Rearranging Cells
        6. Dynamic Cells
      8. Table View Menus
      9. Collection Views
        1. Collection View Classes
        2. Using a Collection View
        3. Custom Collection View Layouts
        4. Switching Layouts
        5. Collection Views and UIKit Dynamics
    4. 9. Popovers and Split Views
      1. Popovers
        1. Preparing a Popover
          1. Arrow source and direction
          2. Popover size and position
          3. Popover appearance
          4. Passthrough views
        2. Popover Presentation, Dismissal, and Delegate
        3. Adaptive Popovers
        4. Popover Segues
        5. Popover Presenting a View Controller
        6. Popover Search Results
      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. Setting the Collapsed State
        6. Replacing the Child View Controllers
        7. Split View Controller in a Storyboard
    5. 10. Text
      1. Fonts and Font Descriptors
        1. Fonts
          1. Dynamic Type fonts
          2. Adding fonts
        2. Font Descriptors
      2. Attributed Strings
        1. Attributed String Attributes
        2. Making an Attributed String
          1. Tab stops
          2. Text attachments
          3. Other ways to create 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. Label Resizing
        4. Customized Label Drawing
      4. Text Fields
        1. Summoning and Dismissing the Keyboard
        2. Keyboard Covers Text Field
          1. Sliding the interface
          2. Text field in a scroll view
        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. WKWebView Content
        2. Tracking Changes in a WKWebView
        3. WKWebView Navigation
        4. Communicating With a WKWebView Web Page
      2. UIWebView
        1. UIWebView Content
        2. UIWebView Navigation
        3. Communicating with a UIWebView
        4. Paginated Web Views
        5. UIWebView State Restoration
      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. Local Notifications
        1. Registering a Notification
        2. Scheduling a Notification
        3. Hearing About a Local Notification
        4. Today Extensions
      3. Activity Views
        1. Presenting an Activity View
        2. Custom Activities
        3. Action Extensions
          1. Action extension without an interface
          2. Action extension with an interface
          3. Receiving data from an action extension
  4. III. Some Frameworks
    1. 14. Audio
      1. System Sounds
      2. Audio Session
        1. Interruptions
        2. Secondary Audio
        3. Routing Changes
      3. Audio Player
      4. Remote Control of Your Sound
      5. Playing Sound in the Background
      6. AVAudioEngine
      7. Speech Synthesis
      8. Further Topics in Sound
    2. 15. Video
      1. AVPlayerViewController
        1. Fullscreen AVPlayerViewController
        2. Embedded AVPlayerViewController
        3. Other AVPlayerViewController Properties
      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. Exploring the Music Library
        1. Querying the Music Library
        2. Persistence and Change in the Music Library
      2. Music Player
      3. MPVolumeView
      4. Playing Songs With AV Foundation
      5. Media Picker
    4. 17. Photo Library and Image Capture
      1. Photo Library Authorization
      2. Choosing From the Photo Library
      3. Photos Framework
        1. Querying the Photo Library
        2. Modifying the Library
        3. Displaying Images
        4. Editing Images
        5. Photo Editing Extension
      4. Using the Camera
        1. Camera Authorization
        2. Using the Camera with UIImagePickerController
        3. Customizing the Image Capture Interface
        4. Image Capture With AV Foundation
    5. 18. Address Book
      1. Address Book Database
        1. Address Book Authorization
        2. Address Book Changes
        3. Persons and Addresses
      2. Address Book Interface
        1. ABPeoplePickerNavigationController
        2. ABPersonViewController
        3. ABNewPersonViewController
        4. ABUnknownPersonViewController
    6. 19. Calendar
      1. Calendar Database
        1. Calendar Database Authorization
        2. Calendar Database Contents
          1. Calendars
          2. Calendar items
        3. Calendar Database Changes
        4. Creating Calendars and Events
        5. Recurrence
        6. Fetching Events
        7. Reminders
        8. Proximity Alarms
      2. Calendar Interface
        1. EKEventViewController
        2. EKEventEditViewController
        3. EKCalendarChooser
    7. 20. Mail and Messages
      1. Mail Message
      2. Text Message
      3. Twitter Post
    8. 21. 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
    9. 22. Sensors
      1. Core Location
        1. Core Location Authorization
        2. Basic Location Determination
        3. Heading
        4. Background Location
          1. Continuous background location
          2. Location monitoring
      2. Acceleration and Attitude
        1. Shake Events
        2. Raw Acceleration
        3. Gyroscope
        4. Motion Activity
  5. IV. Final Topics
    1. 23. Persistent Storage
      1. The Sandbox
        1. Standard Directories
        2. Visually Inspecting the Sandbox
        3. Basic File Operations
        4. Saving and Reading Files
        5. File Coordinators
      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. 24. Basic Networking
      1. HTTP Requests
        1. Simple HTTP Request
        2. Formal HTTP Request
        3. Encapsulating the Session, Task, and Delegate
        4. Multiple Tasks
        5. Background Downloads
      2. Background App Refresh
      3. In-App Purchases
      4. Bonjour
    3. 25. Threads
      1. Main Thread
      2. Why Threading Is Hard
      3. Blocking the Main Thread
      4. NSOperation
      5. Grand Central Dispatch
      6. Threads and App Backgrounding
    4. 26. Undo
      1. Undo Manager
        1. Target–Action Undo
        2. Undo Grouping
        3. Invocation Undo
      2. Undo Interface
        1. Shake-To-Edit
        2. Undo Menu
    5. A. Application Lifetime Events
    6. B. Some Useful Utility Functions
      1. Delayed Performance
      2. Center of a CGRect
      3. Adjust a CGSize
      4. Dictionary of Views
      5. Constraint Issues
      6. Drawing Into an Image Context
      7. Finite Repetition of an Animation
      8. Remove Multiple Indexes From Array
      9. Configure a Value Class At the Point of Use
      10. Cancelable Closure-Based Timer
      11. Generic Wrapper
  6. Index
  7. Colophon
  8. Copyright