WWDC 2015

Getting Started with Multitasking on iPad in iOS 9

Despite the demise of iPad in recent years, Apple put many efforts to improve the user experience of iPad. Multitasking is somewhat long-wanted feature in iPad. This session is introducing how developers to embrace the new technologies in Multitasking.

Great article about multitasking

Related Sesssion: Multitasking Esstials for Media-based Apps on iPad in iOS 9, Optimizing Your App for Multitasking in iOS

Multitasking in your app

Slide Over

right slide over app has compact horizontal size class

Split View

Adaptivity

Adding Multitasking to your app

iPad Multitasking is enabled by default in new project

Existing app

  • build app with iOS 9 SDK
    • base SDK as Latest SDK
  • Support all orientations
  • Use Launch Storyboards
    • Launch Screen files launch screen xib
    • if app requires full screen
      • consider to opt out UIRequiresFullscreen key

UIScreen.bounds returns windows.bounds Only need to care The current UIWindow

* a UILayoutGuide for legible region in a UIView 
* smartly adjust when windows bounds change

```UITableView.cellLayoutMarginsFollowReadableWidth
  • Adds margins to cell for Legibility

Change of UIKit to Multitasking

Related Sesssion: Building Adaptive apps with UIKit (WWDC14)

  • Orientations
//not apply for multitasking as you may be much rooms in different direction
if UIInterfaceOrientationIsLandscape(interfaceOrientation) {
}
//encourage
if view.bounds.size.width > view.bounds.size.height {
}

//encourage
if traitCopllection.horizontalSizeClass == .Regular 
}

in iOS 9 no need to set frame on window as iOS 9 figure out for you so it is okay to initial UIWindow without frame

var window = UIWindow()
or
UIWindow *window = [[UIWindow alloc] init];

PresentationController Related Sesssion: Building Adaptive apps with UIKit (WWDC14)

UIAdaptivePresentationControllerDelegate te response the size changes

Popover To handle popover arrow pointing to right position, these below are suggested.

popoverPresentationController.barButtonItem = sender
OR
popoverPresentationController.sourceView = button
popoverPresentationController.sourceRect = button.bounds

Keyboard listen to the following notification when related keyboard

UIKeyboardWillShowNotification
UIKeyboardDidShowNotification
UIKeyboardWillHideNotification
UIKeyboardDidHideNotification
UIKeyboardWillChangeFrameNotification
UIKeyboardDidChangeFrameNotification

Best Practices

  • Consider size and size classes instead of orientation
  • Think about how to respond to transition
  • Use adaptive presentation

Making the most of multitasking

  • Make your app Universal — iPhone and iPad
  • Design user experiences for Compact and Regular widths
  • Use Adaptivity to change between them

Strategies

  1. Be flexible for all multitasking
    • Slide Over (Compact width)
    • Half screen (Compact width)
    • full screen (Regular width)
    • Rotation
  2. Auto Layout
    • Related Session Mysteries of Auto Layout, Part 1 and Part 2
    • use margin and guide provided by system to have readable content regardless size classes changes
let label = UILabel()
let readableContentGuide = self.view.readableContentGuide
let constraints = [label.leadingAnchor.constraintEqualToAnchor(
readableContentGuide.leadingAnchor), label.trailingAnchor.constraintEqualToAnchor(
readableContentGuide.trailingAnchor) NSLayoutConstraint.activateConstraints(constraints)
  1. Xcode Support

    • Using Interface builder for constraints supports
    • Asset Catalog is also support size classes so any resource can apply different size classes
    • use preview to provide live view and see how the views response to difference size classes
  2. Adaptivity callbacks

override func willTransitionToTraitCollection(
  newCollection: UITraitCollection,
  withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator)
{
    super.willTransitionToTraitCollection(newCollection,
        withTransitionCoordinator:coordinator)
    switch newCollection.horizontalSizeClass {
    case .Compact:
        // Change your UI for a compact width
    case .Regular:
        // Change your UI for a regular width
    case .Unspecified:
        break   // Do nothing
    }

    //do below if animation is needed for size class changes
    let animation = {
        (context: UIViewControllerTransitionCoordinatorContext) -> Void in
        // Change your UI here. It will animate from the old to the new.
    }
    coordinator.animateAlongsideTransition(animation, completion: nil)
}

//another callback for overriding
override func viewWillTransitionToSize(
  size: CGSize,
  withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator)
{ 
}

5: High-level API

* ```UIStackView``` *Related session Mysteries of Auto Layout, Part 1*

6: SplitViewController

Demo Project:AdaptivePhotos

Guidelines

  • The app cannot prevent size changes
  • It cannot cause size changes either
  • Size changes can happen at any time
  • Keep user oriented
    • After size classes change, the screen should show what it showed before size classes change.
    • Remember the current size class and state if needed
  • Performance
    • do little work as possible when size classes change
    • Completion block for slow work
    • In animation block , don't call layoutIfneeded
    • Use setNeedsLayout to mark any views and system will layout for you in the animation