Slide 1

Slide 1 text

Hands On with Adaptive Layout github.com/sammyd/ HandsOnAdaptiveLayout

Slide 2

Slide 2 text

hi, i’m sam @iwantmyrealname

Slide 3

Slide 3 text

shinobicontrols.com/ ios8cocoa

Slide 4

Slide 4 text

shinobicontrols

Slide 5

Slide 5 text

shinobicontrols

Slide 6

Slide 6 text

in the beginning

Slide 7

Slide 7 text

in the beginning

Slide 8

Slide 8 text

in the beginning

Slide 9

Slide 9 text

in the beginning

Slide 10

Slide 10 text

in the beginning

Slide 11

Slide 11 text

in the beginning

Slide 12

Slide 12 text

in the beginning 2 2 2 2 2 = 10 + + + +

Slide 13

Slide 13 text

in the past

Slide 14

Slide 14 text

in the past if UIDevice.currentDevice().userInterfaceIdiom == .Pad { if UIDevice.currentDevice().orientation == .LandscapeLeft || UIDevice.currentDevice().orientation == .LandscapeRight { doSomething() } else { doSomethingElse() } } else { if UIDevice.currentDevice().orientation == .LandscapeLeft || UIDevice.currentDevice().orientation == .LandscapeRight { yetAnotherAlternative() } else { theFourthWay() } }

Slide 15

Slide 15 text

this doesn’t scale

Slide 16

Slide 16 text

adaptive layout introducing….

Slide 17

Slide 17 text

adaptive layout • Abstracts layout away from device specifics • Introduces size classes • Available in iOS 8 • Fully supported in Xcode and IB

Slide 18

Slide 18 text

today • Intro to Size Classes • Demo of installable constraints & views in IB • Adaptive fonts and images • Adaptive Layout in code

Slide 19

Slide 19 text

“amount of space available for content”

Slide 20

Slide 20 text

size classes HORIZONTAL VERTICAL

Slide 21

Slide 21 text

size classes HORIZONTAL VERTICAL compact regular

Slide 22

Slide 22 text

size classes Horizontal Vertical iPad Portrait Regular Regular iPad Landscape Regular Regular iPhone Portrait Compact Regular iPhone Landscape Compact Compact iPhone 6 Plus Landscape Regular Compact

Slide 23

Slide 23 text

approach 1. Build base layout 2. Choose size class override 3. Uninstall irrelevant constraints 4. Add new constraints specific to size class 5. Rinse and repeat

Slide 24

Slide 24 text

demo

Slide 25

Slide 25 text

installable constraints

Slide 26

Slide 26 text

installable constraints

Slide 27

Slide 27 text

installable views

Slide 28

Slide 28 text

adaptive fonts

Slide 29

Slide 29 text

adaptive imagery

Slide 30

Slide 30 text

code

Slide 31

Slide 31 text

UIUserInterfaceSizeClass enum UIUserInterfaceSizeClass : Int { case Unspecified case Compact case Regular }

Slide 32

Slide 32 text

UITraitCollection class UITraitCollection : NSObject,... { var userInterfaceIdiom: UIUserInterfaceIdiom { get } var displayScale: CGFloat { get } var horizontalSizeClass: UIUserInterfaceSizeClass { get } var verticalSizeClass: UIUserInterfaceSizeClass { get } ... }

Slide 33

Slide 33 text

UITraitEnvironment /*! Trait environments expose a trait collection that describes their environment. */ protocol UITraitEnvironment : NSObjectProtocol { var traitCollection: UITraitCollection { get } ... }

Slide 34

Slide 34 text

UITraitEnvironment /*! Trait environments expose a trait collection that describes their environment. */ protocol UITraitEnvironment : NSObjectProtocol { var traitCollection: UITraitCollection { get } ... } UIScreen UIWindow UIPresentationController UIView UIViewController

Slide 35

Slide 35 text

handling change protocol UITraitEnvironment : NSObjectProtocol { ... /*! To be overridden as needed to provide custom behavior when the environment's traits change. */ func traitCollectionDidChange( previousTraitCollection: UITraitCollection?) } UIScreen UIWindow UIPresentationController UIView UIViewController

Slide 36

Slide 36 text

handling change protocol UIContentContainer : NSObjectProtocol { func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) func willTransitionToTraitCollection(newCollection: UITraitCollection, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) } UIScreen UIWindow UIPresentationController UIView UIViewController

Slide 37

Slide 37 text

overriding func setOverrideTraitCollection(collection: UITraitCollection?, forChildViewController childViewController: UIViewController) func overrideTraitCollectionForChildViewController( childViewController: UIViewController) -> UITraitCollection! UIScreen UIWindow UIPresentationController UIView UIViewController

Slide 38

Slide 38 text

where next?

Slide 39

Slide 39 text

where next? • Adaptive View Controller Hierarchies • Adaptive Presentation • WWDC Videos • Ray Wenderlich blog posts / book

Slide 40

Slide 40 text

takeaways • Universal storyboards FTW • Can go far without code • Size classes conceptually equivalent to subclassing

Slide 41

Slide 41 text

don’t be afraid of Auto Layout

Slide 42

Slide 42 text

learn by doing

Slide 43

Slide 43 text

learn by doing thanks @iwantmyrealname github.com/sammyd speakerdeck.com/sammyd