responsive ios collection views

43
Responsive iOS Collection Views 09 / 06 / 2016 Andrea Bizzotto

Upload: andrea-bizzotto

Post on 11-Apr-2017

297 views

Category:

Software


2 download

TRANSCRIPT

Responsive iOSCollection Views

09 / 06 / 2016

Andrea Bizzotto

Responsive iOSCollection Views

09 / 06 / 2016

Andrea Bizzotto

(oh, and size classes…)

Responsive?

Year 2010

Year 2010

Year 2010if UI_USER_INTERFACE_IDIOM() == .Pad { // iPad layout code here}else { // iPhone layout code here}

CGSizeMake(1024, 768)UIScreen.mainScreen().bounds.size// What about interface orientation?

if UI_USER_INTERFACE_IDIOM() == .Pad { // iPad layout code here}else { // iPhone layout code here}

CGSizeMake(1024, 768)UIScreen.mainScreen().bounds.size// What about interface orientation?

Year 2010

if UI_USER_INTERFACE_IDIOM() == .Pad { // iPad layout code here}else { // iPhone layout code here}

CGSizeMake(1024, 768)UIScreen.mainScreen().bounds.size// What about interface orientation?

Year 2010

if UI_USER_INTERFACE_IDIOM() == .Pad { // iPad layout code here}else { // iPhone layout code here}

CGSizeMake(1024, 768)UIScreen.mainScreen().bounds.size// What about interface orientation?

Year 2010

😱

Year 2012

Year 2012NSLayoutConstraint

Springs & Strouts

Auto-Layout

UIView.frame Input Output

Year 2014

Year 2014

Size Classes

Auto-Layout (iOS 6)

Split Views (iOS 9)

Size Classes (iOS 8)

Stack Views (iOS 9)

Apple wants you Auto-Layout (iOS 6)

Split Views (iOS 9)

Size Classes (iOS 8)

Stack Views (iOS 9)

NSLayoutConstraint

Before Size Classes

NSLayoutConstraint

Any

AnyCompact Regular

x3

Any

Compact Regular

x3

Any

Compact Regular

What about the code?

if UI_USER_INTERFACE_IDIOM() == .Pad { // iPad layout code here}else { // iPhone layout code here}

if UI_USER_INTERFACE_IDIOM() == .Pad { // iPad layout code here}else { // iPhone layout code here}

Bad

if UI_USER_INTERFACE_IDIOM() == .Pad { // iPad layout code here}else { // iPhone layout code here}

Bad

if UI_USER_INTERFACE_IDIOM() == .Pad { // iPad layout code here}else { // iPhone layout code here}

// in your view controller:let traitCollection: UITraitCollection = self.traitCollectionswitch traitCollection.horizontalSizeClass { case .Regular: // do this case .Compact: // do that case .Unspecified: // look this up: https://dayone.me/uJGzoW}switch traitCollection.verticalSizeClass {// same thing}// What about interface orientation?

Bad

Good

UI_USER_INTERFACE_IDIOM() UITraitCollection

Changes Neverat runtime

(interface rotation,split view updates)

Scope Everywhere(it’s a macro) UIViewController

func traitCollectionDidChange(previousTraitCollection: UITraitCollection?)

Responsive Collection Views

• Case Study: the iOS Photos app

• Compact layout and Regular layout are quite different

Demo Time

Summary• Universal apps: think ahead (even if PO tells you MVP is iPhone or iPad

only)

• Bonus: teach responsive layouts to designers

• Don’t: UI_USER_INTERFACE_IDIOM()

• Do: Size Classes & UITraitCollections

• You will get split view support for free

• Your app will work on new screen sizes

• Do your layouts in IB, only resort to code you can’t do it in IB

• If you can: use Stack Views

• WWDC….

(Personal opinion)

Summary• Universal apps: think ahead (even if PO tells you MVP is iPhone or iPad

only)

• Bonus: teach responsive layouts to designers

• Don’t: UI_USER_INTERFACE_IDIOM()

• Do: Size Classes & UITraitCollections

• You will get split view support for free

• Your app will work on new screen sizes

• Do your layouts in IB, only resort to code you can’t do it in IB

• If you can: use Stack Views

• WWDC….

(Personal opinion)

Summary• Universal apps: think ahead (even if PO tells you MVP is iPhone or iPad

only)

• Bonus: teach responsive layouts to designers

• Don’t: UI_USER_INTERFACE_IDIOM()

• Do: Size Classes & UITraitCollections

• You will get split view support for free

• Your app will work on new screen sizes

• Do your layouts in IB, only resort to code you can’t do it in IB

• If you can: use Stack Views

• WWDC….

(Personal opinion)

Summary• Universal apps: think ahead (even if PO tells you MVP is iPhone or iPad

only)

• Bonus: teach responsive layouts to designers

• Don’t: UI_USER_INTERFACE_IDIOM()

• Do: Size Classes & UITraitCollections

• You will get split view support for free

• Your app will work on new screen sizes

• Do your layouts in IB, only resort to code you can’t do it in IB

• If you can: use Stack Views

• WWDC….

(Personal opinion)

Summary• Universal apps: think ahead (even if PO tells you MVP is iPhone or iPad

only)

• Bonus: teach responsive layouts to designers

• Don’t: UI_USER_INTERFACE_IDIOM()

• Do: Size Classes & UITraitCollections

• You will get split view support for free

• Your app will work on new screen sizes

• Do your layouts in IB, only resort to code you can’t do it in IB

• If you can: use Stack Views

• WWDC….

(Personal opinion)

Summary• Universal apps: think ahead (even if PO tells you MVP is iPhone or iPad

only)

• Bonus: teach responsive layouts to designers

• Don’t: UI_USER_INTERFACE_IDIOM()

• Do: Size Classes & UITraitCollections

• You will get split view support for free 💪👏😃

• Your app will work on new screen sizes

• Do your layouts in IB, only resort to code you can’t do it in IB

• If you can: use Stack Views

• WWDC….

(Personal opinion)

Summary• Universal apps: think ahead (even if PO tells you MVP is iPhone or iPad

only)

• Bonus: teach responsive layouts to designers

• Don’t: UI_USER_INTERFACE_IDIOM()

• Do: Size Classes & UITraitCollections

• You will get split view support for free 💪👏😃

• Your app will work on new screen sizes

• Do your layouts in IB, only resort to code you can’t do it in IB

• If you can: use Stack Views

• WWDC….

(Personal opinion)

Summary• Universal apps: think ahead (even if PO tells you MVP is iPhone or iPad

only)

• Bonus: teach responsive layouts to designers

• Don’t: UI_USER_INTERFACE_IDIOM()

• Do: Size Classes & UITraitCollections

• You will get split view support for free 💪👏😃

• Your app will work on new screen sizes

• Do your layouts in IB, only resort to code you can’t do it in IB

• If you can: use Stack Views

• WWDC….

(Personal opinion)

Summary• Universal apps: think ahead (even if PO tells you MVP is iPhone or iPad

only)

• Bonus: teach responsive layouts to designers

• Don’t: UI_USER_INTERFACE_IDIOM()

• Do: Size Classes & UITraitCollections

• You will get split view support for free 💪👏😃

• Your app will work on new screen sizes

• Do your layouts in IB, only resort to code you can’t do it in IB

• If you can: use Stack Views

• WWDC….

(Personal opinion)

Summary• Universal apps: think ahead (even if PO tells you MVP is iPhone or iPad

only)

• Bonus: teach responsive layouts to designers

• Don’t: UI_USER_INTERFACE_IDIOM()

• Do: Size Classes & UITraitCollections

• You will get split view support for free 💪👏😃

• Your app will work on new screen sizes

• Do your layouts in IB, only resort to code you can’t do it in IB

• If you can: use Stack Views

• WWDC….

(Personal opinion)

Thank Youhttps://github.com/bizz84/ResponsiveCollectionViews

Twitter: @biz84

blog: http://bizz84.github.io/