192
© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. #WWDC14 A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks Jim Turner UIKit Engineer

228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

#WWDC14

A Look Inside Presentation ControllersWith a case study on alerts and search

Session 228 Peter Hajas UIKit Engineer

Frameworks

!

Jim Turner UIKit Engineer

Page 2: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Intro

Page 3: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Intro

Animator objects

Page 4: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Intro

Animator objects• Custom presentation difficult

Page 5: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Intro

Animator objects• Custom presentation difficult

UIPresentationController

Page 6: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Agenda

Page 7: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Agenda

Presentation basics

Page 8: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Agenda

Presentation basics

UIKit presentations

Page 9: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Agenda

Presentation basics

UIKit presentations

Demo

Page 10: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!
Page 11: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!
Page 12: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!
Page 13: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Presented

Page 14: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Presented

Presenting

Page 15: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Content

Presented

Page 16: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Chrome

Presenting

Page 17: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Hello, UIPresentationController

Page 18: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Hello, UIPresentationController

Presentation management

Page 19: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Hello, UIPresentationController

Presentation management

Animates

Page 20: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Hello, UIPresentationController

Presentation management

Animates

Trait and size changes

Page 21: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Hello, UIPresentationController

Presentation management

Animates

Trait and size changes

Reusable

Page 22: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPresentationControllerDivision of responsibilities

Page 23: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPresentationControllerDivision of responsibilities

Animator object

Page 24: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPresentationControllerDivision of responsibilities

Animator object

Animating controller content

Page 25: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPresentationControllerDivision of responsibilities

Animator object

Animating controller content

Positioning

Page 26: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPresentationControllerDivision of responsibilities

Animator object

Animating controller content

Positioning

Chrome

Page 27: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPresentationControllerDivision of responsibilities

Animator object Presentation controller

Animating controller content

Positioning

Chrome

Page 28: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPresentationControllerDivision of responsibilities

Animator object Presentation controller

Animating controller content Positioning

Chrome

Page 29: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPresentationControllerDivision of responsibilities

Animator object Presentation controller

Animating controller content Positioning

Chrome

Adaptation

Page 30: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIKit PresentationsPopovers, alerts, action sheets, and search

Page 31: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPopoverPresentationController

Page 32: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPopoverPresentationController

Replacing UIPopoverController

Page 33: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPopoverPresentationController

Replacing UIPopoverController

Functionally equivalent

Page 34: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPopoverPresentationController

Replacing UIPopoverController

Functionally equivalent

Built-in adaptivity

Page 35: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPopoverControllerOld API

UIViewController *contentController = …; UIPopoverController *poc = [[UIPopoverController alloc] initWithContentViewController:contentController]; [poc presentPopoverFromBarButtonItem:item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Page 36: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPopoverControllerOld API

UIViewController *contentController = …; !

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { UIPopoverController *poc = [[UIPopoverController alloc] initWithContentViewController:contentController]; !

[poc presentPopoverFromBarButtonItem:item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } !

else { [self presentViewController:contentController …]; }

Page 37: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPopoverPresentationControllerNew API

contentController.modalPresentationStyle = UIModalPresentationPopover; UIPopoverPresentationController *popPC = contentController.popoverPresentationController; popPC.barButtonItem = item; popPC.permittedArrowDirections = UIPopoverArrowDirectionAny; [self presentViewController:contentController animated:YES completion:nil];

Page 38: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPopoverPresentationControllerNew API

contentController.modalPresentationStyle = UIModalPresentationPopover; UIPopoverPresentationController *popPC = contentController.popoverPresentationController; popPC.barButtonItem = item; popPC.permittedArrowDirections = UIPopoverArrowDirectionAny; [self presentViewController:contentController animated:YES completion:nil];

Page 39: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPopoverPresentationControllerNew API

contentController.modalPresentationStyle = UIModalPresentationPopover; UIPopoverPresentationController *popPC = contentController.popoverPresentationController; popPC.barButtonItem = item; popPC.permittedArrowDirections = UIPopoverArrowDirectionAny; [self presentViewController:contentController animated:YES completion:nil];

Page 40: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPopoverPresentationControllerNew API

contentController.modalPresentationStyle = UIModalPresentationPopover; UIPopoverPresentationController *popPC = contentController.popoverPresentationController; popPC.barButtonItem = item; popPC.permittedArrowDirections = UIPopoverArrowDirectionAny; [self presentViewController:contentController animated:YES completion:nil];

Page 41: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPopoverPresentationControllerNew API

contentController.modalPresentationStyle = UIModalPresentationPopover; UIPopoverPresentationController *popPC = contentController.popoverPresentationController; popPC.barButtonItem = item; popPC.permittedArrowDirections = UIPopoverArrowDirectionAny; [self presentViewController:contentController animated:YES completion:nil];

Page 42: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

DemoAdaptive popovers

Page 43: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPopoverPresentationControllerFullscreen adaptation

contentController.modalPresentationStyle = UIModalPresentationPopover; UIPopoverPresentationController *popPC = contentController.popoverPresentationController; popPC.barButtonItem = item; popPC.permittedArrowDirections = UIPopoverArrowDirectionAny; !

[self presentViewController:contentController animated:YES completion:nil];

P

Page 44: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPopoverPresentationControllerFullscreen adaptation

contentController.modalPresentationStyle = UIModalPresentationPopover; UIPopoverPresentationController *popPC = contentController.popoverPresentationController; popPC.barButtonItem = item; popPC.permittedArrowDirections = UIPopoverArrowDirectionAny; popPC.delegate = self; !

[self presentViewController:contentController animated:YES completion:nil];

P

Page 45: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPopoverPresentationControllerFullscreen adaptation

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller { return UIModalPresentationFullScreen; }

P

Page 46: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPopoverPresentationControllerFullscreen adaptation

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller { return UIModalPresentationFullScreen; } !

- (UIViewController *)presentationController:(UIPresentationController *)controller viewControllerForAdaptivePresentationStyle:(UIModalPresentationStyle)style { UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller.presentedViewController]; return navController; }

P

Page 47: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Alerts and Action SheetsUIAlertView and UIActionSheet

Page 48: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Alerts and Action SheetsUIAlertView and UIActionSheet

Page 49: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Alerts and Action SheetsUIAlertView and UIActionSheet

Used to be plain views

Page 50: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Alerts and Action SheetsUIAlertView and UIActionSheet

Used to be plain views

New window for presentation

Page 51: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Alerts and Action SheetsUIAlertView and UIActionSheet

Used to be plain views

New window for presentation

Predate modern language features

Page 52: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Alerts and Action SheetsOld alerts presentation

Page 53: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Alerts and Action SheetsOld alerts presentation

App Content

Page 54: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Alerts and Action SheetsOld alerts presentation

App ContentAlert Window

Page 55: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Alerts and Action SheetsOld alerts presentation

App Content

Aler

t Win

dow

Page 56: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Alerts and Action SheetsOld alerts presentation

App Content

Aler

t Win

dow

Page 57: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Alerts and Action SheetsOld alerts presentation

App Content

Aler

t Win

dow

Page 58: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIAlertController

Page 59: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIAlertController

Used for alerts and action sheets

Page 60: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIAlertController

Used for alerts and action sheets

Block based

Page 61: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIAlertController

Used for alerts and action sheets

Block based

Presents in your window

Page 62: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIAlertController

Used for alerts and action sheets

Block based

Presents in your window

Action sheets adapt to popovers

Page 63: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIAlertControllerNew API

UIAlertController* sheet = [UIAlertController alertControllerWithTitle:...]; [sheet addAction:[UIAlertAction actionWithTitle:@“Reply” style:UIAlertActionStyleDefault handler:^void (UIAlertAction *action) { // do stuff }]; !

[self presentViewController:sheet...];

Page 64: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIAlertControllerNew API

UIAlertController* sheet = [UIAlertController alertControllerWithTitle:...]; [sheet addAction:[UIAlertAction actionWithTitle:@“Reply” style:UIAlertActionStyleDefault handler:^void (UIAlertAction *action) { // do stuff }]; !

[self presentViewController:sheet...];

Page 65: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIAlertControllerNew API

UIAlertController* sheet = [UIAlertController alertControllerWithTitle:...]; [sheet addAction:[UIAlertAction actionWithTitle:@“Reply” style:UIAlertActionStyleDefault handler:^void (UIAlertAction *action) { // do stuff }]; !

[self presentViewController:sheet...];

Page 66: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIAlertControllerNew API

UIAlertController* sheet = [UIAlertController alertControllerWithTitle:...]; [sheet addAction:[UIAlertAction actionWithTitle:@“Reply” style:UIAlertActionStyleDefault handler:^void (UIAlertAction *action) { // do stuff }]; !

[self presentViewController:sheet...];

Page 67: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

SearchUISearchDisplayController

Page 68: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

SearchUISearchDisplayController

Page 69: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

SearchUISearchDisplayController

Page 70: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

SearchUISearchDisplayController

Limited configurability

Page 71: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

SearchUISearchDisplayController

Limited configurability

Ambiguous intent

Page 72: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

SearchUISearchDisplayController

Limited configurability

Ambiguous intent

“Presented” via addSubview:

Page 73: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

SearchUISearchDisplayController

Limited configurability

Ambiguous intent

“Presented” via addSubview:

Search Bar

Page 74: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

SearchUISearchDisplayController

Limited configurability

Ambiguous intent

“Presented” via addSubview:

Search Content

Search Bar

Page 75: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

SearchUISearchDisplayController

Limited configurability

Ambiguous intent

“Presented” via addSubview:

Search Content

Search Bar

Page 76: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchController

Page 77: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchController

Replaces UISearchDisplayController

Page 78: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchController

Replaces UISearchDisplayController

Any presenting controller

Page 79: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchController

Replaces UISearchDisplayController

Any presenting controller

Decoupled results

Page 80: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchController

Replaces UISearchDisplayController

Any presenting controller

Decoupled results

Search bar animation

Page 81: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchController

Replaces UISearchDisplayController

Any presenting controller

Decoupled results

Search bar animation

Adaptivity

Page 82: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchController

Replaces UISearchDisplayController

Any presenting controller

Decoupled results

Search bar animation

Adaptivity

More control, fewer assumptions

Page 83: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchDisplayControllerOld API

UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero]; UISearchDisplayController *searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self]; searchController.searchResultsDataSource = self; searchController.searchResultsDelegate = self; self.tableView.tableHeaderView = searchController.searchBar;

Page 84: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchControllerNew API

MyResultsController *resultsController = [[MyResultsController alloc] init]; !

UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:resultsController]; searchController.searchResultsUpdater = resultsController; self.tableView.tableHeaderView = searchController.searchBar; self.definesPresentationContext = YES;

Page 85: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchControllerNew API

MyResultsController *resultsController = [[MyResultsController alloc] init]; !

UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:resultsController]; searchController.searchResultsUpdater = resultsController; self.tableView.tableHeaderView = searchController.searchBar; self.definesPresentationContext = YES;

Page 86: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchControllerNew API

MyResultsController *resultsController = [[MyResultsController alloc] init]; !

UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:resultsController]; searchController.searchResultsUpdater = resultsController; self.tableView.tableHeaderView = searchController.searchBar; self.definesPresentationContext = YES;

Page 87: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchControllerNew API

MyResultsController *resultsController = [[MyResultsController alloc] init]; !

UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:resultsController]; searchController.searchResultsUpdater = resultsController; self.tableView.tableHeaderView = searchController.searchBar; self.definesPresentationContext = YES;

Page 88: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchControllerNew API

MyResultsController *resultsController = [[MyResultsController alloc] init]; !

UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:resultsController]; searchController.searchResultsUpdater = resultsController; self.tableView.tableHeaderView = searchController.searchBar; self.definesPresentationContext = YES;

Page 89: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchControllerNew API

MyResultsController *resultsController = [[MyResultsController alloc] init]; !

UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:resultsController]; searchController.searchResultsUpdater = resultsController; self.tableView.tableHeaderView = searchController.searchBar; self.definesPresentationContext = YES;

Page 90: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Search Results

Tab Bar

Search Bar

UISearchControllerNew API

Table View Controller

Navigation Bar

Tab Bar

Search Bar

Page 91: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Search Results

Tab Bar

Search Bar

UISearchControllerNew API

Table View Controller

Navigation Bar

Tab Bar

Search Bar

Page 92: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchControllerNew API

Search Results

Tab Bar

Search Bar

Table View Controller

Navigation Bar

Tab Bar

Search Bar

Page 93: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UISearchControllerNew API

Search Results

Search Bar

Table View Controller

Navigation Bar

Tab Bar

Search Bar

Page 94: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPresentationControllerBenefits

Page 95: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPresentationControllerBenefits

Controllers all the way down

Page 96: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPresentationControllerBenefits

Controllers all the way down

Content and chrome abstraction

Page 97: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIPresentationControllerBenefits

Controllers all the way down

Content and chrome abstraction

Adaptivity

Page 98: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

DemoLet’s build something new

Page 99: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Presenting the Overlay View ControllerMain view controller

OverlayViewController* overlay = [[OverlayViewController alloc] init]; [overlay setPhoto:photo]; !

[self presentViewController:overlay animated:YES completion:NULL];

P

Page 100: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Presenting the Overlay View ControllerMain view controller

OverlayViewController* overlay = [[OverlayViewController alloc] init]; [overlay setPhoto:photo]; !

[self presentViewController:overlay animated:YES completion:NULL];

P

Page 101: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Root View Controller

Page 102: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Root View ControllerOverlay View Controller

Page 103: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Root View Controller

Page 104: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Root View Controller Overlay View Controller

Page 105: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay Presentation

Root View Controller Overlay View Controller

Transitioning Delegate

Page 106: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay Presentation

Root View Controller Overlay View Controller

Transitioning Delegate

Animator Object

Page 107: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay Presentation

Root View Controller Overlay View Controller

Transitioning Delegate

Animator Object Presentation Controller

Page 108: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay PresentationRoot view controller

transitionDelegate = [[OverlayTransitioningDelegate alloc] init]; [overlayViewController setTransitioningDelegate:transitionDelegate];

P

Page 109: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay PresentationRoot view controller

transitionDelegate = [[OverlayTransitioningDelegate alloc] init]; [overlayViewController setTransitioningDelegate:transitionDelegate];

P

Page 110: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

OVCCustomizing the Overlay PresentationOverlay view controller

[self setModalPresentationStyle:UIModalPresentationCustom];

Page 111: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay PresentationProviding a custom UIPresentationController

- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source { return [[OverlayPresentationController alloc] initWithPresentingViewController:presenting presentedViewController:presented]; }

TD

Page 112: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay PresentationPresentation controller animations

- (void)presentationTransitionWillBegin { UIView* containerView = [self containerView]; UIViewController* presentedViewController = [self presentedViewController]; [dimmingView setFrame:[containerView bounds]]; [dimmingView setAlpha:0.0]; !

[containerView insertSubview:dimmingView atIndex:0]; [[presentedViewController transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { [dimmingView setAlpha:1.0]; } completion:nil]; }

PC

Page 113: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay PresentationPresentation controller animations

- (void)presentationTransitionWillBegin { UIView* containerView = [self containerView]; UIViewController* presentedViewController = [self presentedViewController]; [dimmingView setFrame:[containerView bounds]]; [dimmingView setAlpha:0.0]; !

[containerView insertSubview:dimmingView atIndex:0]; [[presentedViewController transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { [dimmingView setAlpha:1.0]; } completion:nil]; }

PC

Page 114: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay PresentationPresentation controller animations

- (void)presentationTransitionWillBegin { UIView* containerView = [self containerView]; UIViewController* presentedViewController = [self presentedViewController]; [dimmingView setFrame:[containerView bounds]]; [dimmingView setAlpha:0.0]; !

[containerView insertSubview:dimmingView atIndex:0]; [[presentedViewController transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { [dimmingView setAlpha:1.0]; } completion:nil]; }

PC

Page 115: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay PresentationPresentation controller animations

- (void)dismissalTransitionWillBegin { [[[self presentedViewController] transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { [dimmingView setAlpha:0.0]; } completion:nil]; }

PC

Page 116: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Root View Controller

Page 117: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Root View Controller

Page 118: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay PresentationTransitioning delegate animations

- (id <UIViewControllerAnimatedTransitioning>) animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { OverlayAnimatedTransitioning *animationController = [[OverlayAnimatedTransitioning alloc] init]; return animationController; }

TD

Page 119: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay PresentationTransitioning delegate animations

- (id <UIViewControllerAnimatedTransitioning>) animationControllerForDismissedController:(UIViewController *)dismissed { OverlayAnimatedTransitioning *animationController = [[OverlayAnimatedTransitioning alloc] init]; return animationController; }

TD

Page 120: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay PresentationPresented view controller sizing

- (CGSize)sizeForChildContentContainer:(id <UIContentContainer>)container withParentContainerSize:(CGSize)parentSize { return CGSizeMake(floorf(parentSize.width / 3.0), parentSize.height); }

PC

Page 121: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay PresentationPresented view controller sizing

- (CGRect)frameOfPresentedViewInContainerView { CGRect presentedViewFrame = CGRectZero; CGRect containerBounds = [[self containerView] bounds]; presentedViewFrame.size = [self sizeForChildContentContainer:(UIView<UIContentContainer> *)[self presentedView] withParentContainerSize:containerBounds.size]; presentedViewFrame.origin.x = containerBounds.size.width - presentedViewFrame.size.width; return presentedViewFrame; }

PC

Page 122: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Root

Vie

w C

ontr

olle

rO

verla

y Vi

ew

Cont

rolle

r

Root View Controller Overlay View Controller

Page 123: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Root View Controller Overlay View Controller

Root View Controller

Overlay View

Controller

Page 124: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Root View Controller

Overlay View

Controller

Root View Controller Overlay View ControllerRoot View Controller Overlay View Controller

Page 125: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay PresentationAdding rotation support

- (void)containerViewWillLayoutSubviews { [dimmingView setFrame:[[self containerView] bounds]]; [[self presentedView] setFrame:[self frameOfPresentedViewInContainerView]]; }

PC

Page 126: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Customizing the Overlay PresentationAdding rotation support

- (void)containerViewWillLayoutSubviews { [dimmingView setFrame:[[self containerView] bounds]]; [[self presentedView] setFrame:[self frameOfPresentedViewInContainerView]]; }

PC

Page 127: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainer

Page 128: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainer

UIViewController

Page 129: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainer

UIViewController

UIPresentationController

Page 130: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainer

UIViewController

UIPresentationController

Environment changes

Page 131: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerTransitioning to size

Page 132: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerTransitioning to size

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator

Page 133: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerTransitioning to size

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator- (CGSize)sizeForChildContentContainer:(id <UIContentContainer>)container withParentContainerSize:(CGSize)parentSize

Page 134: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerTransitioning to size

Page 135: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerTransitioning to size

!Root

Controller

Child 2

Child 1

Page 136: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerTransitioning to size

[root presentViewController:presented …];

!Root

Controller Presented Controller

Child 2

Child 1

Page 137: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerTransitioning to size

[root presentViewController:presented …];

!Root

Controller Presented Controller

Presentation Controller

Child 2

Child 1

Page 138: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

!Root

Controller

UIContentContainerTransitioning to size

Presented Controller

Presentation Controller

Child 2

Child 1

Page 139: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

!Root

Controller

UIContentContainerTransitioning to size

viewWillTransitionToSize:withTransitionCoordinator:

Presented Controller

Presentation Controller

Child 2

Child 1

Page 140: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

!Root

Controller

UIContentContainerTransitioning to size

viewWillTransitionToSize:withTransitionCoordinator:

Presented Controller

Presentation Controller

Child 2

Child 1

Page 141: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

!Root

Controller

UIContentContainerTransitioning to size

viewWillTransitionToSize:withTransitionCoordinator:

Presented Controller

Presentation Controller

Child 2

Child 1

Page 142: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

!Root

Controller

UIContentContainerTransitioning to size

viewWillTransitionToSize:withTransitionCoordinator:

Presented Controller

Presentation Controller

Child 2

Child 1

[Root sizeForChildContentContainer:Child1 withParentContainerSize:size]

Page 143: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

!Root

Controller

UIContentContainerTransitioning to size

viewWillTransitionToSize:withTransitionCoordinator:

Presented Controller

Presentation Controller

Child 2

Child 1

[Root sizeForChildContentContainer:Child2 withParentContainerSize:size]

Page 144: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

!Root

Controller

UIContentContainerTransitioning to size

viewWillTransitionToSize:withTransitionCoordinator:

Presented Controller

Presentation Controller

Child 2

Child 1

Page 145: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

!Root

Controller

UIContentContainerTransitioning to size

viewWillTransitionToSize:withTransitionCoordinator:

Presented Controller

Presentation Controller

Child 2

Child 1

[Presentation sizeForChildContentContainer:Presented withParentContainerSize:size]

Page 146: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

!Root

Controller

UIContentContainerTransitioning to size

viewWillTransitionToSize:withTransitionCoordinator:

Presented Controller

Presentation Controller

Child 2

Child 1

Page 147: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerPreferred content size

Page 148: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerPreferred content size

@property (nonatomic, readonly) CGSize preferredContentSize

Page 149: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerPreferred content size

@property (nonatomic, readonly) CGSize preferredContentSize

- (void)preferredContentSizeDidChangeForChildContentContainer:(id <UIContentContainer>)container

Page 150: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerPreferred content size

!Root

Controller Presented Controller

Presentation Controller

Child 2

Child 1

Page 151: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerPreferred content size

setPreferredContentSize:

!Root

Controller Presented Controller

Presentation Controller

Child 2

Child 1

Page 152: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerPreferred content size

preferredContentSizeDidChangeForChildContentContainer:

!Root

Controller Presented Controller

Presentation Controller

Child 2

Child 1

Page 153: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerPreferred content size

viewWillTransitionToSize:withTransitionCoordinator:

!Root

Controller Presented Controller

Presentation Controller

Child 2

Child 1

Page 154: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerPreferred content size

!Root

ControllerPresented Controller

Presentation Controller

Child 2

Child 1

Page 155: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerTrait collections

Page 156: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

UIContentContainerTrait collections

- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator

Page 157: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Trait Collections

@property (nonatomic, readonly) UIUserInterfaceSizeClass horizontalSizeClass; @property (nonatomic, readonly) UIUserInterfaceSizeClass verticalSizeClass; @property (nonatomic, readonly) UIUserInterfaceIdiom userInterfaceIdiom; @property (nonatomic, readonly) CGFloat displayScale;

horizontalSizeClass

verticalSizeClass

userInterfaceIdiom

displayScale

Page 158: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Trait Collections

@property (nonatomic, readonly) UIUserInterfaceSizeClass horizontalSizeClass; @property (nonatomic, readonly) UIUserInterfaceSizeClass verticalSizeClass; @property (nonatomic, readonly) UIUserInterfaceIdiom userInterfaceIdiom; @property (nonatomic, readonly) CGFloat displayScale;

horizontalSizeClass Compact

verticalSizeClass

userInterfaceIdiom

displayScale

Regular

Phone

2.0

Page 159: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

Page 160: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator

Page 161: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator

Page 162: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator- (void)containerViewWillLayoutSubviews- (void)viewWillLayoutSubviews

Page 163: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

Page 164: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

willTransitionToTraitCollection

Page 165: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

willTransitionToTraitCollection• Coarse-grain control

Page 166: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

willTransitionToTraitCollection• Coarse-grain control

• Adaptivity

Page 167: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

willTransitionToTraitCollection• Coarse-grain control

• Adaptivity

• Screens

Page 168: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

willTransitionToTraitCollection• Coarse-grain control

• Adaptivity

• Screens

• Auto-hiding status bar

Page 169: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

Page 170: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

viewWillTransitionToSize

Page 171: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

viewWillTransitionToSize• Medium-grain control

Page 172: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

viewWillTransitionToSize• Medium-grain control

• Child controller size requests

Page 173: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

viewWillTransitionToSize• Medium-grain control

• Child controller size requests

• Rotation

Page 174: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

viewWillTransitionToSize• Medium-grain control

• Child controller size requests

• Rotation

• Resizable simulator

Page 175: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

Page 176: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

containerViewWillLayoutSubviews and viewWillLayoutSubviews

Page 177: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

containerViewWillLayoutSubviews and viewWillLayoutSubviews• Fine-grain control

Page 178: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

containerViewWillLayoutSubviews and viewWillLayoutSubviews• Fine-grain control

• Resize subviews

Page 179: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Responding to Changes

containerViewWillLayoutSubviews and viewWillLayoutSubviews• Fine-grain control

• Resize subviews

• Child container views

Page 180: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

DemoAdaptivity and multiple presentation controllers

Page 181: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Adding a New Presentation StyleRoot view controller

transitionDelegate = [[OverlayTransitioningDelegate alloc] init]; [overlayViewController setTransitioningDelegate:transitionDelegate];

P

Page 182: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Adding a New Presentation StyleRoot view controller

if([self presentationShouldBeAwesome]) { transitioningDelegate = [[CoolTransitioningDelegate alloc] init]; } else { transitioningDelegate = [[OverlayTransitioningDelegate alloc] init]; } !

[overlay setTransitioningDelegate:transitioningDelegate];

P

Page 183: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Adding a New Presentation StyleRoot view controller

if([self presentationShouldBeAwesome]) { transitioningDelegate = [[CoolTransitioningDelegate alloc] init]; } else { transitioningDelegate = [[OverlayTransitioningDelegate alloc] init]; } !

[overlay setTransitioningDelegate:transitioningDelegate];

P

Page 184: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Adding a New Presentation StyleRoot view controller

if([self presentationShouldBeAwesome]) { transitioningDelegate = [[CoolTransitioningDelegate alloc] init]; } else { transitioningDelegate = [[OverlayTransitioningDelegate alloc] init]; } !

[overlay setTransitioningDelegate:transitioningDelegate];

P

Page 185: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Summary

Page 186: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Summary

Improved API through UIAlertController and UISearchController

Page 187: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Summary

Improved API through UIAlertController and UISearchController

Presentations are now in your hands

Page 188: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Summary

Improved API through UIAlertController and UISearchController

Presentations are now in your hands• Go make your own Cool Mode!

Page 189: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

More Information

Jake Behrens App Frameworks Evangelist [email protected]

Documentation View Controllers and Presentation Controllers http://developer.apple.com

Apple Developer Forums http://devforums.apple.com

Page 190: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Related Sessions

• View Controller Advancements in iOS 8 Mission Wednesday 9:00AM

• Building Adaptive Apps with UIKit Mission Wednesday 10:15AM

• What's New in Interface Builder Mission Wednesday 3:15PM

• Core iOS Application Architectural Patterns Mission Thursday 9:00AM

Page 191: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!

Labs

• Cocoa Touch Lab Frameworks Lab A Thursday 2:00PM

Page 192: 228 A Look Inside Presentation Controllers 02 DF€¦ · A Look Inside Presentation Controllers With a case study on alerts and search Session 228 Peter Hajas UIKit Engineer Frameworks!