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

Responsive iOS Collection Views

Apr 11, 2017

Download

Software

Andrea Bizzotto
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Responsive iOS Collection Views

Responsive iOSCollection Views

09 / 06 / 2016

Andrea Bizzotto

Page 2: Responsive iOS Collection Views

Responsive iOSCollection Views

09 / 06 / 2016

Andrea Bizzotto

(oh, and size classes…)

Page 3: Responsive iOS Collection Views

Responsive?

Page 4: Responsive iOS Collection Views

Year 2010

Page 5: Responsive iOS Collection Views

Year 2010

Page 6: Responsive iOS Collection Views

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?

Page 7: Responsive iOS Collection Views

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

Page 8: Responsive iOS Collection Views

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

Page 9: Responsive iOS Collection Views

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

😱

Page 10: Responsive iOS Collection Views

Year 2012

Page 11: Responsive iOS Collection Views

Year 2012NSLayoutConstraint

Springs & Strouts

Auto-Layout

UIView.frame Input Output

Page 12: Responsive iOS Collection Views

Year 2014

Page 13: Responsive iOS Collection Views

Year 2014

Size Classes

Page 14: Responsive iOS Collection Views
Page 15: Responsive iOS Collection Views
Page 16: Responsive iOS Collection Views
Page 17: Responsive iOS Collection Views
Page 18: Responsive iOS Collection Views

Auto-Layout (iOS 6)

Split Views (iOS 9)

Size Classes (iOS 8)

Stack Views (iOS 9)

Page 19: Responsive iOS Collection Views

Apple wants you Auto-Layout (iOS 6)

Split Views (iOS 9)

Size Classes (iOS 8)

Stack Views (iOS 9)

Page 20: Responsive iOS Collection Views

NSLayoutConstraint

Before Size Classes

Page 21: Responsive iOS Collection Views

NSLayoutConstraint

Any

Page 22: Responsive iOS Collection Views

AnyCompact Regular

x3

Page 23: Responsive iOS Collection Views

Any

Compact Regular

x3

Page 24: Responsive iOS Collection Views

Any

Compact Regular

Page 25: Responsive iOS Collection Views

What about the code?

Page 26: Responsive iOS Collection Views

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

Page 27: Responsive iOS Collection Views

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

Bad

Page 28: Responsive iOS Collection Views

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

Bad

Page 29: Responsive iOS Collection Views

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

Page 30: Responsive iOS Collection Views

UI_USER_INTERFACE_IDIOM() UITraitCollection

Changes Neverat runtime

(interface rotation,split view updates)

Scope Everywhere(it’s a macro) UIViewController

func traitCollectionDidChange(previousTraitCollection: UITraitCollection?)

Page 31: Responsive iOS Collection Views

Responsive Collection Views

• Case Study: the iOS Photos app

• Compact layout and Regular layout are quite different

Page 32: Responsive iOS Collection Views

Demo Time

Page 33: Responsive iOS Collection Views

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)

Page 34: Responsive iOS Collection Views

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)

Page 35: Responsive iOS Collection Views

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)

Page 36: Responsive iOS Collection Views

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)

Page 37: Responsive iOS Collection Views

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)

Page 38: Responsive iOS Collection Views

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)

Page 39: Responsive iOS Collection Views

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)

Page 40: Responsive iOS Collection Views

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)

Page 41: Responsive iOS Collection Views

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)

Page 42: Responsive iOS Collection Views

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)

Page 43: Responsive iOS Collection Views

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

Twitter: @biz84

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