adapting to adaptive ui

32
Adapting to Adaptive UI Светослав Величков iOS жонгльор

Upload: despark

Post on 18-Jun-2015

1.371 views

Category:

Technology


1 download

DESCRIPTION

What's coming with iOS8 and why use Auto Layout and reactive web design for native iOS apps. Despark is a digital boutique that specializes in web, mobile & tablet projects. The work that we do in the studio is split between our own as well as projects for a range of startups, blue-chip brands, International corporations and local firms. Find us at despark.com.

TRANSCRIPT

Page 1: Adapting to Adaptive UI

Adapting to Adaptive UI

Светослав ВеличковiOS жонгльор

Page 2: Adapting to Adaptive UI

Какво ни очаква?

• Adaptive UI • Auto Layout & Asset Catalog • Size Classes, Trait Collections & Trait Environments • Content Containers & Presentation Controllers

iOS 8

iOS 8

(следващите 25 минути и в бъдещето на iOS)

Page 3: Adapting to Adaptive UI

Adaptive какво? Какъв UI?

Page 4: Adapting to Adaptive UI

“Ще спестим милиони от ремонт на износени i и f клавиши!”

– Craig Federighi (предполагам)

Page 5: Adapting to Adaptive UI

if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )

if ( UIInterfaceOrientationIsPortrait(orientation) )

if ( IS_IPHONE5() )

#define IS_IPHONE5() \ ([[UIScreen mainScreen] bounds].size.height == 568)

Page 6: Adapting to Adaptive UI

Reactive Web Design for Native iOS Apps

Page 7: Adapting to Adaptive UI

Какво е Auto Layout?

Инертен интерфейс vs

Адаптивен интерфейс

Page 8: Adapting to Adaptive UI

Защо Auto Layout?

• Концептуално оформление на UI • По-малко код — по-малко грешки • Опростена локализация • Изключително подходящ за адаптивен UI

Page 9: Adapting to Adaptive UI

Защо не ползваме Auto Layout?

• Interface Builder в Xcode 4

• Многословно API в код

• Анимации без -setFrame:

Page 10: Adapting to Adaptive UI

Interface Builder в Xcode 5+Вече с 200% повече страхотна Auto Layout поддръжка и

витамин C!

Page 11: Adapting to Adaptive UI

Auto Layout в код@interface UIView (MPSAutoLayout) !- (NSLayoutConstraint*)mps_attachViewBelowView:(UIView*)previousView padding:(CGFloat)padding; !@end !@implementation UIView (MPSAutoLayout) !- (NSLayoutConstraint*)mps_attachViewBelowView:(UIView*)previousView padding:(CGFloat)padding; { NSLayoutConstraint* constraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:previousView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:padding]; UIView* commonAncestor = [self mps_commonAncestorViewWithView:previousView]; [commonAncestor addConstraint:constraint]; return constraint; }

Page 12: Adapting to Adaptive UI

• https://github.com/smileyborg/PureLayout

• https://github.com/erica/Auto-Layout-Demystified

• https://github.com/rentzsch/AutoLayoutShorthand

Page 13: Adapting to Adaptive UI

Анимация с Auto Layout

• подмяна на NSLayoutConstraints • промяна на constant • промяна на priority — по-добре не

Page 14: Adapting to Adaptive UI

Asset Catalog

Page 15: Adapting to Adaptive UI

Size Classes

typedef NS_ENUM (NSInteger, UIUserInterfaceSizeClass { UIUserInterfaceSizeClassUnspecified = 0, UIUserInterfaceSizeClassCompact = 1, UIUserInterfaceSizeClassRegular = 2, };

Page 16: Adapting to Adaptive UI

UITraitCollection

UITraitCollection • horizontalSizeClass • verticalSizeClass • userInterfaceIdiom (UI_USER_INTERFACE_IDIOM()) • displayScale

Page 17: Adapting to Adaptive UI

UITraitEnvironment

- traitCollection - traitCollectionDidChange:

Page 18: Adapting to Adaptive UI

UITraitEnvironment

• UIScreen • UIWindow • UIView • UIViewController • UIPresentationController

Page 19: Adapting to Adaptive UI

Специална поддръжка на UITraitCollection

• UIImage (UIImageAsset) • UIAppearance

Page 20: Adapting to Adaptive UI

Size Class MatrixCompact Regular

Compact iPhone landscape —

Regular iPhone portrait iPad

Page 21: Adapting to Adaptive UI

Size Class MatrixCompact Regular

Compact

Regular

Page 22: Adapting to Adaptive UI

• UIViewController - overrideTraitCollectionForChildViewController: - setOverrideTraitCollection:forChildViewController:

• UIPresentationController @property overrideTraitCollection

Page 23: Adapting to Adaptive UI

• UISplitViewController / UINavigationController - showViewController:sender: - showDetailViewController:sender:

Page 24: Adapting to Adaptive UI

UIViewControllerRotation

- willRotateToInterfaceOrientation:duration: - didRotateFromInterfaceOrientation: - willAnimateRotationToInterfaceOrientation:

- viewWillTransitionToSize:withTransitionCoordinator:

Page 25: Adapting to Adaptive UI

UIPresentationControllerне UIViewController subclass

Page 26: Adapting to Adaptive UI
Page 27: Adapting to Adaptive UI

Как работи

• id <UIViewControllerTransitioningDelegate> • - presentationControllerForPresentedViewController:

presentingViewController: sourceViewController:

• presentationController.delegate = presentingViewController • - presentationController:viewControllerForAdaptivePresentationStyle:

Page 28: Adapting to Adaptive UI

Какъв е резултатът

• UIPopoverController • UIAlertController • UISearchController (≠ UISearchDisplayController)

Page 29: Adapting to Adaptive UI

Xcode 6 Interface Builder

Demo

Page 30: Adapting to Adaptive UI

Обобщение• Мигрирайте към Auto Layout • Използвайте Asset Catalog • iOS 8

• Единен Storyboard за всички размери екрани • traitCollectionDidChange: • Забравете UIInterfaceOrientation и

UIViewControllerRotation • Модални контролери чрез UIPresentationController

Page 31: Adapting to Adaptive UI

Полезни WWDC'14 сесии:

• 216 - Building Adaptive Apps with UIKit • 228 - A Look Inside Presentation Controllers • 214 - View Controller Advancements in iOS 8 • 411 - What's New in Interface Builder • 233 - Sharing code between iOS and OS X • 221 - Creating Custom iOS User Interfaces

Page 32: Adapting to Adaptive UI

Светослав Величков[email protected]