•advanced touch bar - apple inc....touch bar fundamentals grand ballroom a wednesday 10:00amfile...

286
#WWDC17 © 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. Donna Tom, TextKit Jeff Nadeau, AppKit Taylor Kelly, AppKit Advanced Touch Bar Session 222 App Frameworks

Upload: others

Post on 17-May-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

#WWDC17

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

Donna Tom, TextKit Jeff Nadeau, AppKit Taylor Kelly, AppKit

•Advanced Touch Bar • Session 222

App Frameworks

Page 2: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Touch Bar Fundamentals

•Grand Ballroom A •Wednesday, 10:00AM

Page 3: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSScrubber

Building Custom Controls

Customizing Text Bars

Page 4: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSScrubber

Building Custom Controls

Customizing Text Bars

Page 5: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Standard items •Disabling standard items •Adding custom items •Candidate list item

Page 6: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Standard items •Disabling standard items •Adding custom items •Candidate list item

Page 7: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Standard Items

Page 8: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Standard Items

QuickType

Page 9: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Standard Items

Character picker

QuickType

Page 10: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Standard Items

Character picker

QuickTypeColor picker

11

Page 11: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Standard Items

Character picker

Formatting QuickTypeColor picker

12

Page 12: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Standard Items

Character picker

Formatting Alignmentand list

QuickTypeColor picker

12

Page 13: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTextView NSTouchBardelegate

Page 14: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTextView NSTouchBardelegate

NSTextFieldfield editor

Page 15: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Standard Items Field editor considerations

Window Field Editor

Text Field Text Field Text Field

Page 16: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Standard Items Field editor considerations

Window Field Editor

Text Field Text Field Text Field

Page 17: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Standard items •Disabling standard items •Adding custom items •Candidate list item

Page 18: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Disabling Standard Items

// Disable QuickType suggestions textView.isAutomaticTextCompletionEnabled = false

// Disable character picker textView.allowsCharacterPickerTouchBarItem = false

// Disable text styling controls — different properties for NSTextView and NSTextField textView.isRichText = false textField.allowsEditingTextAttributes = false

Page 19: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Disabling Standard Items

// Disable QuickType suggestions textView.isAutomaticTextCompletionEnabled = false

// Disable character picker textView.allowsCharacterPickerTouchBarItem = false

// Disable text styling controls — different properties for NSTextView and NSTextField textView.isRichText = false textField.allowsEditingTextAttributes = false

Page 20: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286
Page 21: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286
Page 22: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Standard items •Disabling standard items •Adding custom items •Candidate list item

Page 23: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Adding Custom Items

Page 24: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// It’s tempting to simply add it to the text view’s defaultItemIdentifiers var newItems = textView.touchBar?.defaultItemIdentifiers newItems.append(.myNewButton) textView.touchBar?.defaultItemIdentifiers = newItems

Page 25: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// It’s tempting to simply add it to the text view’s defaultItemIdentifiers var newItems = textView.touchBar?.defaultItemIdentifiers newItems.append(.myNewButton) textView.touchBar?.defaultItemIdentifiers = newItems

Please don’t do this.

Page 26: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// It’s tempting to simply add it to the text view’s defaultItemIdentifiers var newItems = textView.touchBar?.defaultItemIdentifiers newItems.append(.myNewButton) textView.touchBar?.defaultItemIdentifiers = newItems

Please don’t do this. 😭

Page 27: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286
Page 28: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286
Page 29: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

makeItemForIdentifier: .candidateList

Page 30: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

makeItemForIdentifier: .candidateList

makeItemForIdentifier: .characterPicker

Page 31: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

makeItemForIdentifier: .candidateList

makeItemForIdentifier: .characterPicker

makeItemForIdentifier: .myNewButton

Page 32: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

makeItemForIdentifier: .candidateList

makeItemForIdentifier: .characterPicker

makeItemForIdentifier: .myNewButton ☹

Page 33: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Approach #1: •Use higher-level responder

Page 34: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Adding Custom Items Approach #1: Higher-level responder

Page 35: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Adding Custom Items Approach #1: Higher-level responder

Page 36: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Adding Custom Items : Higher-level responder

class MessageViewController: NSViewController {

}

Page 37: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Adding Custom Items : Higher-level responder

class MessageViewController: NSViewController { override func makeTouchBar() -> NSTouchBar {

} }

Page 38: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Adding Custom Items : Higher-level responder

class MessageViewController: NSViewController { override func makeTouchBar() -> NSTouchBar { let item = NSCustomTouchBarItem(identifier: .sendButton) item.view = NSButton(image: NSImage(named: .send), target: self, action: #selector(ViewController.send(_:))

} }

Page 39: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Adding Custom Items : Higher-level responder

class MessageViewController: NSViewController { override func makeTouchBar() -> NSTouchBar { let item = NSCustomTouchBarItem(identifier: .sendButton) item.view = NSButton(image: NSImage(named: .send), target: self, action: #selector(ViewController.send(_:))

} }

Page 40: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Adding Custom Items : Higher-level responder

class MessageViewController: NSViewController { override func makeTouchBar() -> NSTouchBar { let item = NSCustomTouchBarItem(identifier: .sendButton) item.view = NSButton(image: NSImage(named: .send), target: self, action: #selector(ViewController.send(_:)) let touchBar = NSTouchBar() touchBar.templateItems = [item] touchBar.defaultItemIdentifiers = [.sendButton, .otherItemsProxy] return touchBar } }

Page 41: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Adding Custom Items : Higher-level responder

class MessageViewController: NSViewController { override func makeTouchBar() -> NSTouchBar { let item = NSCustomTouchBarItem(identifier: .sendButton) item.view = NSButton(image: NSImage(named: .send), target: self, action: #selector(ViewController.send(_:)) let touchBar = NSTouchBar() touchBar.templateItems = [item] touchBar.defaultItemIdentifiers = [.sendButton, .otherItemsProxy] return touchBar } }

Page 42: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Adding Custom Items : Higher-level responder

class MessageViewController: NSViewController { override func makeTouchBar() -> NSTouchBar { let item = NSCustomTouchBarItem(identifier: .sendButton) item.view = NSButton(image: NSImage(named: .send), target: self, action: #selector(ViewController.send(_:)) let touchBar = NSTouchBar() touchBar.templateItems = [item] touchBar.defaultItemIdentifiers = [.sendButton, .otherItemsProxy] return touchBar } }

Page 43: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Approach #2: •Subclass NSTextView

Page 44: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Adding Custom Items Approach #2: Subclassing NSTextView

Page 45: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Adding Custom Items Approach #2: Subclassing NSTextView

Page 46: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Adding Custom Items Approach #2: Subclassing NSTextView

override func updateTouchBarItemIdentifiers() { super.updateTouchBarItemIdentifiers() // Add your custom NSTouchBarItem.Identifier to defaultItemIdentifiers }

Page 47: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Adding Custom Items Approach #2: Subclassing NSTextView

override func updateTouchBarItemIdentifiers() { super.updateTouchBarItemIdentifiers() // Add your custom NSTouchBarItem.Identifier to defaultItemIdentifiers }

override func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? { let item = super.touchBar(touchBar, makeItemForIdentifier: identifier) // If item is nil, check the identifier and create your custom NSTouchBarItem }

Page 48: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Adding Custom Items Approach #2: Subclassing NSTextView

override func updateTouchBarItemIdentifiers() { super.updateTouchBarItemIdentifiers() // Add your custom NSTouchBarItem.Identifier to defaultItemIdentifiers }

override func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? { let item = super.touchBar(touchBar, makeItemForIdentifier: identifier) // If item is nil, check the identifier and create your custom NSTouchBarItem }

Page 49: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Standard items •Disabling standard items •Adding custom items •Candidate list item

Page 50: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Candidate List Item

Page 51: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Candidate List Item

Page 52: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTextView

NSTouchBarvar touchBar

NSCandidateListTouchBarItemvar candidateListTouchBarItem

Page 53: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTextView

NSTouchBarvar touchBar

NSCandidateListTouchBarItemvar candidateListTouchBarItem

NSTextFieldfield editor

Page 54: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Candidate Sources

QuickType

System input method

Custom

Page 55: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Approach #1: •Use delegation

Page 56: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidates Approach #1: Use delegation

protocol NSTextFieldDelegate { optional func textField(_ textField: NSTextField, textView: NSTextView, candidatesForSelectedRange selectedRange: NSRange) -> [Any]? }

protocol NSTextViewDelegate { optional func textView(_ textView: NSTextView, candidatesForSelectedRange selectedRange: NSRange) -> [Any]? }

Page 57: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Approach #2: •Use higher-level responder

Page 58: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidates Approach #2: Use higher-level responder

NSWindow

NSViewController

Page 59: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidates Approach #2: Use higher-level responder

NSTextField

NSTouchBar

NSCandidateListTouchBarItem

NSWindow

NSViewController

Page 60: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Example: •Email Autocomplete

Page 61: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidates Email autocomplete

Page 62: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidates Email autocomplete

Page 63: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidates Email autocomplete

candidateListItem.allowsCollapsing = false

Page 64: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidates Email autocomplete

candidateListItem.allowsCollapsing = false

Page 65: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidates Email autocomplete

candidateListItem.allowsCollapsing = false

Not collapsible!

Page 66: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Window Field Editor

Text Field Text Field Text Field

Setting .allowsCollapsing will affect all text fields in the window

Page 67: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Window Field Editor

Text Field Text Field Text Field

Setting .allowsCollapsing will affect all text fields in the window

Page 68: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Candidates : Subclassing NSTextFieldCell

class CustomTextFieldCell: NSTextFieldCell { var fieldEditor : NSTextView?

}

Page 69: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Candidates : Subclassing NSTextFieldCell

class CustomTextFieldCell: NSTextFieldCell { var fieldEditor : NSTextView? override func fieldEditor(for controlView: NSView) -> NSTextView? {

} }

Page 70: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Candidates : Subclassing NSTextFieldCell

class CustomTextFieldCell: NSTextFieldCell { var fieldEditor : NSTextView? override func fieldEditor(for controlView: NSView) -> NSTextView? {

} }

Page 71: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Candidates : Subclassing NSTextFieldCell

class CustomTextFieldCell: NSTextFieldCell { var fieldEditor : NSTextView? override func fieldEditor(for controlView: NSView) -> NSTextView? { if self.fieldEditor == nil { let editor = NSTextView(frame: controlView.frame) editor.isFieldEditor = true editor.delegate = controlView as? NSTextViewDelegate

self.fieldEditor = editor } return self.fieldEditor } }

Page 72: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Candidates : Subclassing NSTextFieldCell

class CustomTextFieldCell: NSTextFieldCell { var fieldEditor : NSTextView? override func fieldEditor(for controlView: NSView) -> NSTextView? { if self.fieldEditor == nil { let editor = NSTextView(frame: controlView.frame) editor.isFieldEditor = true editor.delegate = controlView as? NSTextViewDelegate

self.fieldEditor = editor } return self.fieldEditor } }

Page 73: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Candidates : Implementing Delegate

class ViewController: NSViewController, NSTextFieldDelegate { func textField(_ textField: NSTextField, textView: NSTextView, candidatesForSelectedRange selectedRange: NSRange) -> [Any]? {

textView.candidateListTouchBarItem?.allowsCollapsing = false

// Add your code here for returning array of custom candidates } }

Page 74: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Candidates : Implementing Delegate

class ViewController: NSViewController, NSTextFieldDelegate { func textField(_ textField: NSTextField, textView: NSTextView, candidatesForSelectedRange selectedRange: NSRange) -> [Any]? {

textView.candidateListTouchBarItem?.allowsCollapsing = false

// Add your code here for returning array of custom candidates } }

Page 75: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidate List Item •Approach #2: Use higher-level responder

Disable QuickType

Create custom candidate list item

Implement delegate method

Update candidates on text input

Page 76: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidate List Item •Approach #2: Use higher-level responder

textField.isAutomaticTextCompletionEnabled = false

Page 77: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidate List Item •Approach #2: Use higher-level responder

func touchBar( _ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier ) -> NSTouchBarItem? {

// Create NSCandidateListTouchBarItem here

}

Page 78: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidate List Item •Approach #2: Use higher-level responder

func touchBar( _ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier ) -> NSTouchBarItem? {

// Create NSCandidateListTouchBarItem here

}

Page 79: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidate List Item •Approach #2: Use higher-level responder

func touchBar( _ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier ) -> NSTouchBarItem? {

// Create NSCandidateListTouchBarItem here

}

// Return the string to display for each candidate candidateListItem.attributedStringForCandidate = { [unowned self] (candidate, index) -> NSAttributedString in

return NSAttributedString(string:”Your Custom Attributed String”) }

Page 80: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidate List Item •Approach #2: Use higher-level responder

func candidateListTouchBarItem(_ anItem: NSCandidateListTouchBarItem<AnyObject>, endSelectingCandidateAt index: Int) {

// Return your model object candidate here }

Page 81: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidate List Item •Approach #2: Use higher-level responder

override func controlTextDidChange(_ notification: Notification) { // Fetch the candidates for the current text input

// Set the candidates candidateListItem.setCandidates(candidates, forSelectedRange: range, in: nil)

}

Page 82: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Custom Candidate List Item •Approach #2: Use higher-level responder

override func controlTextDidChange(_ notification: Notification) { // Fetch the candidates for the current text input

// Set the candidates candidateListItem.setCandidates(candidates, forSelectedRange: range, in: nil)

}

Page 83: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSScrubber

Building Custom Controls

Customizing Text Bars

Page 84: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSScrubber

Building Custom Controls

Customizing Text Bars

Page 85: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Versatile Control for Touch Bar

Calendar Timeline

Safari Tabs

Keynote Slides

Page 86: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Versatile Control for Touch Bar

Calendar Timeline

Safari Tabs

Keynote Slides

Page 87: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Versatile Control for Touch Bar

Calendar Timeline

Safari Tabs

Keynote Slides

Page 88: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

What is NSScrubber?

Arranges a collection of content

Gesture-based highlighting and selection

API similar to NSCollectionView

Page 89: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

What is NSScrubber?

May 28 — 3May 21 — 27 Jun 11 — 17 Jun 18 — 24Jun 4 – 10

Page 90: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

What is NSScrubber?

May 28 — 3May 21 — 27 Jun 11 — 17 Jun 18 — 24Jun 4 – 10

Page 91: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

What is NSScrubber?

May 28 — 3May 21 — 27 Jun 11 — 17 Jun 18 — 24Jun 4 – 10

Page 92: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

What is NSScrubber?

May 28 — 3May 21 — 27 Jun 11 — 17 Jun 18 — 24Jun 4 – 10

Page 93: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

What is NSScrubber?

May 28 — 3May 21 — 27 Jun 11 — 17 Jun 18 — 24Jun 4 – 10

Page 94: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

What is NSScrubber?

May 28 — 3May 21 — 27 Jun 11 — 17 Jun 18 — 24Jun 4 – 10

Page 95: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Configuring NSScrubber •Defining a Layout •Providing Content •Responding to Input

Page 96: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Configuring NSScrubber •Defining a Layout •Providing Content •Responding to Input

Page 97: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Two Ways to Interact with Content

class NSScrubber { var mode: NSScrubber.Mode }

case fixed

case free

Page 98: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Continuous Selection

class NSScrubber { var isContinuous: Bool }

Page 99: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Continuous Selection

scrubber.isContinuous = false

class NSScrubber { var isContinuous: Bool }

Page 100: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Continuous Selection

scrubber.isContinuous = true

class NSScrubber { var isContinuous: Bool }

Page 101: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Continuous Selection

scrubber.isContinuous = false

class NSScrubber { var isContinuous: Bool }

Page 102: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Continuous Selection

scrubber.isContinuous = true

class NSScrubber { var isContinuous: Bool }

Page 103: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Selection Styles

class NSScrubber { var selectionBackgroundStyle: NSScrubberSelectionStyle?

var selectionOverlayStyle: NSScrubberSelectionStyle? }

class NSScrubberSelectionStyle { class var outlineOverlay: NSScrubberSelectionStyle { get } class var roundedBackground: NSScrubberSelectionStyle { get } }

Page 104: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Selection Styles

class NSScrubber { var selectionBackgroundStyle: NSScrubberSelectionStyle?

var selectionOverlayStyle: NSScrubberSelectionStyle? }

class NSScrubberSelectionStyle { class var outlineOverlay: NSScrubberSelectionStyle { get } class var roundedBackground: NSScrubberSelectionStyle { get } }

Page 105: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Selection Styles

class NSScrubber { var selectionBackgroundStyle: NSScrubberSelectionStyle?

var selectionOverlayStyle: NSScrubberSelectionStyle? }

class NSScrubberSelectionStyle { class var outlineOverlay: NSScrubberSelectionStyle { get } class var roundedBackground: NSScrubberSelectionStyle { get } }

Page 106: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Floating Selection

scrubber.floatsSelectionViews = false

class NSScrubber { var floatsSelectionViews: Bool }

Page 107: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Floating Selection

scrubber.floatsSelectionViews = true

class NSScrubber { var floatsSelectionViews: Bool }

Page 108: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Preferred Alignment

class NSScrubber { enum ItemAlignment { case none, leading, trailing, center }

var itemAlignment: NSScrubber.ItemAlignment

}

Page 109: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Appearance

class NSScrubber { var backgroundColor: NSColor?

var backgroundView: NSView? }

Page 110: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Appearance

class NSScrubber { var backgroundColor: NSColor?

var backgroundView: NSView? }

class NSColor { class var scrubberTexturedBackground: NSColor { get } }

Page 111: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

let scrubber = NSScrubber() scrubber.scrubberLayout = NSScrubberProportionalLayout(numberOfVisibleItems: 7) scrubber.delegate = self scrubber.dataSource = self

scrubber.mode = .free scrubber.isContinuous = true scrubber.itemAlignment = .center

scrubber.selectionBackgroundStyle = .roundedBackground scrubber.selectionOverlayStyle = .outlineOverlay scrubber.floatsSelectionViews = true

scrubber.backgroundColor = .scrubberTexturedBackground

Page 112: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

let scrubber = NSScrubber() scrubber.scrubberLayout = NSScrubberProportionalLayout(numberOfVisibleItems: 7) scrubber.delegate = self scrubber.dataSource = self

scrubber.mode = .free scrubber.isContinuous = true scrubber.itemAlignment = .center

scrubber.selectionBackgroundStyle = .roundedBackground scrubber.selectionOverlayStyle = .outlineOverlay scrubber.floatsSelectionViews = true

scrubber.backgroundColor = .scrubberTexturedBackground

Page 113: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

let scrubber = NSScrubber() scrubber.scrubberLayout = NSScrubberProportionalLayout(numberOfVisibleItems: 7) scrubber.delegate = self scrubber.dataSource = self

scrubber.mode = .free scrubber.isContinuous = true scrubber.itemAlignment = .center

scrubber.selectionBackgroundStyle = .roundedBackground scrubber.selectionOverlayStyle = .outlineOverlay scrubber.floatsSelectionViews = true

scrubber.backgroundColor = .scrubberTexturedBackground

Page 114: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

let scrubber = NSScrubber() scrubber.scrubberLayout = NSScrubberProportionalLayout(numberOfVisibleItems: 7) scrubber.delegate = self scrubber.dataSource = self

scrubber.mode = .free scrubber.isContinuous = true scrubber.itemAlignment = .center

scrubber.selectionBackgroundStyle = .roundedBackground scrubber.selectionOverlayStyle = .outlineOverlay scrubber.floatsSelectionViews = true

scrubber.backgroundColor = .scrubberTexturedBackground

Page 115: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

let scrubber = NSScrubber() scrubber.scrubberLayout = NSScrubberProportionalLayout(numberOfVisibleItems: 7) scrubber.delegate = self scrubber.dataSource = self

scrubber.mode = .free scrubber.isContinuous = true scrubber.itemAlignment = .center

scrubber.selectionBackgroundStyle = .roundedBackground scrubber.selectionOverlayStyle = .outlineOverlay scrubber.floatsSelectionViews = true

scrubber.backgroundColor = .scrubberTexturedBackground

Page 116: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

let scrubber = NSScrubber() scrubber.scrubberLayout = NSScrubberProportionalLayout(numberOfVisibleItems: 7) scrubber.delegate = self scrubber.dataSource = self

scrubber.mode = .free scrubber.isContinuous = true scrubber.itemAlignment = .center

scrubber.selectionBackgroundStyle = .roundedBackground scrubber.selectionOverlayStyle = .outlineOverlay scrubber.floatsSelectionViews = true

scrubber.backgroundColor = .scrubberTexturedBackground

Page 117: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Configuring NSScrubber •Defining a Layout •Providing Content •Responding to Input

Page 118: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSScrubberLayout

Defines layout of scrubber’s contents

Items described by NSScrubberLayoutAttributes

class NSScrubberLayoutAttributes : NSObject, NSCopying { var itemIndex: Int var frame: NSRect var alpha: CGFloat }

Page 119: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Key Methods in NSScrubberLayout

class NSScrubberLayout : NSObject, NSCoding {

var scrubberContentSize: NSSize func layoutAttributesForItems(in rect: NSRect) -> Set<NSScrubberLayoutAttributes>

func layoutAttributesForItem(at index: Int) -> NSScrubberLayoutAttributes?

}

Page 120: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Key Methods in NSScrubberLayout

class NSScrubberLayout : NSObject, NSCoding {

var scrubberContentSize: NSSize func layoutAttributesForItems(in rect: NSRect) -> Set<NSScrubberLayoutAttributes>

func layoutAttributesForItem(at index: Int) -> NSScrubberLayoutAttributes?

}

Page 121: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Key Methods in NSScrubberLayout

class NSScrubberLayout : NSObject, NSCoding {

var scrubberContentSize: NSSize func layoutAttributesForItems(in rect: NSRect) -> Set<NSScrubberLayoutAttributes>

func layoutAttributesForItem(at index: Int) -> NSScrubberLayoutAttributes?

}

Page 122: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Key Methods in NSScrubberLayout

class NSScrubberLayout : NSObject, NSCoding {

var scrubberContentSize: NSSize func layoutAttributesForItems(in rect: NSRect) -> Set<NSScrubberLayoutAttributes>

func layoutAttributesForItem(at index: Int) -> NSScrubberLayoutAttributes?

}

Page 123: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Key Methods in NSScrubberLayout

class NSScrubberLayout : NSObject, NSCoding {

var scrubberContentSize: NSSize func layoutAttributesForItems(in rect: NSRect) -> Set<NSScrubberLayoutAttributes>

func layoutAttributesForItem(at index: Int) -> NSScrubberLayoutAttributes?

}

Page 124: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Layout Invalidation

Signals that layout has changed

Optional invalidation when selection, highlight, or visible rectangle changes

NSScrubber will call prepare() before the next layout

class NSScrubberLayout { func invalidateLayout() func prepare() }

Page 125: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Configuring NSScrubber •Defining a Layout •Providing Content •Responding to Input

Page 126: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Views

Items are represented using views

Similar to NSTableCellView

Reuse queue

protocol NSScrubberDataSource { /* How many items are there? */ func numberOfItems(for scrubber: NSScrubber) -> Int /* Prepare a view to represent a particular item */ func scrubber(_ scrubber: NSScrubber, viewForItemAt index: Int) -> NSScrubberItemView }

Page 127: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSScrubberTextItemView

class NSScrubberTextItemView : NSScrubberItemView {

var title: String

}

Page 128: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSScrubberImageItemView

class NSScrubberImageItemView : NSScrubberItemView {

var image: NSImage

var imageAlignment: NSImageAlignment

}

Page 129: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Item Views

class NSScrubberItemView : NSScrubberArrangedView { var isSelected: Bool var isHighlighted: Bool func apply(_ layoutAttributes: NSScrubberLayoutAttributes) }

Page 130: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Configuring NSScrubber •Defining a Layout •Providing Content •Responding to Input

Page 131: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Responding to User Input

protocol NSScrubberDelegate {

optional func scrubber(_ scrubber: NSScrubber, didSelectItemAt selectedIndex: Int) optional func scrubber(_ scrubber: NSScrubber, didHighlightItemAt highlightedIndex: Int) optional func scrubber(_ scrubber: NSScrubber, didChangeVisibleRange visibleRange: NSRange)

optional func didBeginInteracting(with scrubber: NSScrubber) optional func didFinishInteracting(with scrubber: NSScrubber) optional func didCancelInteracting(with scrubber: NSScrubber)

}

Page 132: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Responding to User Input

protocol NSScrubberDelegate {

optional func scrubber(_ scrubber: NSScrubber, didSelectItemAt selectedIndex: Int) optional func scrubber(_ scrubber: NSScrubber, didHighlightItemAt highlightedIndex: Int) optional func scrubber(_ scrubber: NSScrubber, didChangeVisibleRange visibleRange: NSRange)

optional func didBeginInteracting(with scrubber: NSScrubber) optional func didFinishInteracting(with scrubber: NSScrubber) optional func didCancelInteracting(with scrubber: NSScrubber)

}

Page 133: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Responding to User Input

protocol NSScrubberDelegate {

optional func scrubber(_ scrubber: NSScrubber, didSelectItemAt selectedIndex: Int) optional func scrubber(_ scrubber: NSScrubber, didHighlightItemAt highlightedIndex: Int) optional func scrubber(_ scrubber: NSScrubber, didChangeVisibleRange visibleRange: NSRange)

optional func didBeginInteracting(with scrubber: NSScrubber) optional func didFinishInteracting(with scrubber: NSScrubber) optional func didCancelInteracting(with scrubber: NSScrubber)

}

Page 134: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Responding to User Input

protocol NSScrubberDelegate {

optional func scrubber(_ scrubber: NSScrubber, didSelectItemAt selectedIndex: Int) optional func scrubber(_ scrubber: NSScrubber, didHighlightItemAt highlightedIndex: Int) optional func scrubber(_ scrubber: NSScrubber, didChangeVisibleRange visibleRange: NSRange)

optional func didBeginInteracting(with scrubber: NSScrubber) optional func didFinishInteracting(with scrubber: NSScrubber) optional func didCancelInteracting(with scrubber: NSScrubber)

}

Page 135: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSScrubber

Building Custom Controls

Customizing Text Bars

Page 136: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSScrubber

Building Custom Controls

Customizing Text Bars

Page 137: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Event Handling •Styling and Appearance •Layout •Animation

Page 138: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Event Handling •Styling and Appearance •Layout •Animation

Page 139: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Touches

Page 140: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Touches

vsDirect Indirect

Page 141: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Direct Indirect

Page 142: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Direct Indirect

Page 143: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Direct Indirect

Page 144: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Direct Indirect

Page 145: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouch

class NSTouch { enum TouchType { case direct case indirect } var type: TouchType { get } }

Page 146: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouch

extension NSTouch { func location(in view: NSView?) -> NSPoint }

Direct touches only

Coordinate space is important

Page 147: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouch NSTouch

let xLocation = touch.location(in: self).x

let newValue = (xLocation / bounds.width).clamp(0, 1)

Page 148: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouch NSTouch

let xLocation = touch.location(in: self).x

let newValue = (xLocation / bounds.width).clamp(0, 1)

Page 149: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouch NSTouch

let xLocation = touch.location(in: self).x

let newValue = (xLocation / bounds.width).clamp(0, 1)

Page 150: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouch NSTouch

let xLocation = touch.location(in: self).x

let newValue = (xLocation / bounds.width).clamp(0, 1)

Page 151: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouch NSTouch

let xLocation = touch.location(in: self).x

let newValue = (xLocation / bounds.width).clamp(0, 1)

0.27

Page 152: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouch

class NSTouch : NSObject, NSCopying {

var identity: NSObjectProtocol & NSCopying { get }

}

Page 153: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouch

class NSTouch : NSObject, NSCopying {

var identity: NSObjectProtocol & NSCopying { get }

}

Page 154: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

class NSTouch : NSObject, NSCopying {

var identity: NSObjectProtocol & NSCopying { get }

}

NSTouch

Page 155: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

class NSTouch : NSObject, NSCopying {

var identity: NSObjectProtocol & NSCopying { get }

}

NSTouch

NSEventNSEventNSEvent NSEvent

Page 156: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

class NSTouch : NSObject, NSCopying {

var identity: NSObjectProtocol & NSCopying { get }

}

NSTouch

NSEventNSEventNSEvent NSEvent

Page 157: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

class NSTouch : NSObject, NSCopying {

var identity: NSObjectProtocol & NSCopying { get }

}

NSTouch

NSEventNSEventNSEvent NSEvent

id = ★id = ♣id = ★id = ★

Page 158: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

class NSTouch : NSObject, NSCopying {

var identity: NSObjectProtocol & NSCopying { get }

}

NSTouch

NSEventNSEventNSEvent NSEvent

id = ★id = ♣id = ★id = ★

Page 159: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouch

API Overview

Diff to UITouch

var trackingTouchID: AnyObject?

// find the first tracking touch guard trackingTouchID == nil else { return }

guard let touch = event1.touches(matching: .began, in: self).first else { return } trackingTouchID = touch.identity

// find successive touches guard let trackingTouchID = trackingTouchID else { return } guard let touch = event2.touches(matching: .moved, in: self).first(where: { $0.identity.isEqual(trackingTouchID) }) else { return }

Page 160: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouch

API Overview

Diff to UITouch

var trackingTouchID: AnyObject?

// find the first tracking touch guard trackingTouchID == nil else { return }

guard let touch = event1.touches(matching: .began, in: self).first else { return } trackingTouchID = touch.identity

// find successive touches guard let trackingTouchID = trackingTouchID else { return } guard let touch = event2.touches(matching: .moved, in: self).first(where: { $0.identity.isEqual(trackingTouchID) }) else { return }

Page 161: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouch

API Overview

Diff to UITouch

var trackingTouchID: AnyObject?

// find the first tracking touch guard trackingTouchID == nil else { return }

guard let touch = event1.touches(matching: .began, in: self).first else { return } trackingTouchID = touch.identity

// find successive touches guard let trackingTouchID = trackingTouchID else { return } guard let touch = event2.touches(matching: .moved, in: self).first(where: { $0.identity.isEqual(trackingTouchID) }) else { return }

Page 162: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouch

API Overview

Diff to UITouch

var trackingTouchID: AnyObject?

// find the first tracking touch guard trackingTouchID == nil else { return }

guard let touch = event1.touches(matching: .began, in: self).first else { return } trackingTouchID = touch.identity

// find successive touches guard let trackingTouchID = trackingTouchID else { return } guard let touch = event2.touches(matching: .moved, in: self).first(where: { $0.identity.isEqual(trackingTouchID) }) else { return }

Page 163: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouch

API Overview

Diff to UITouch

var trackingTouchID: AnyObject?

// find the first tracking touch guard trackingTouchID == nil else { return }

guard let touch = event1.touches(matching: .began, in: self).first else { return } trackingTouchID = touch.identity

// find successive touches guard let trackingTouchID = trackingTouchID else { return } guard let touch = event2.touches(matching: .moved, in: self).first(where: { $0.identity.isEqual(trackingTouchID) }) else { return }

Page 164: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouch

API Overview

Diff to UITouch

var trackingTouchID: AnyObject?

// find the first tracking touch guard trackingTouchID == nil else { return }

guard let touch = event1.touches(matching: .began, in: self).first else { return } trackingTouchID = touch.identity

// find successive touches guard let trackingTouchID = trackingTouchID else { return } guard let touch = event2.touches(matching: .moved, in: self).first(where: { $0.identity.isEqual(trackingTouchID) }) else { return }

Page 165: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSResponder and NSView

Automatic opt-in with 10.12 linking

extension NSResponder {

func touchesBegan(with event: NSEvent)

func touchesMoved(with event: NSEvent)

func touchesEnded(with event: NSEvent)

} func touchesCancelled(with event: NSEvent)

extension NSView {

var allowedTouchTypes: NSTouch.TouchTypeMask

}

Page 166: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSResponder and NSView

Automatic opt-in with 10.12 linking

extension NSResponder {

func touchesBegan(with event: NSEvent)

func touchesMoved(with event: NSEvent)

func touchesEnded(with event: NSEvent)

} func touchesCancelled(with event: NSEvent)

extension NSView {

var allowedTouchTypes: NSTouch.TouchTypeMask

}

Page 167: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSResponder and NSView

Very important in Touch Bar

Changes to Touch Bar content • Focus changes on screen • State changes

Accidental touches

func touchesCancelled(with event: NSEvent)

Page 168: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSGestureRecognizer

Requires opt-in

Only direct touches supported

extension NSGestureRecognizer {

func touchesBegan(with event: NSEvent)

func touchesMoved(with event: NSEvent)

func touchesEnded(with event: NSEvent)

func touchesCancelled(with event: NSEvent)

var allowedTouchTypes: NSTouch.TouchTypeMask

}

Page 169: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSGestureRecognizer

AppKit Touch Bar Support UIKit

NSPressGestureRecognizer UIPressGestureRecognizer

NSPanGestureRecognizer UIPanGestureRecognizer

NSClickGestureRecognizer UITapGestureRecognizer

NSMagnificationGestureRecognizer UIMagnificationGestureRecognizer

Page 170: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSGestureRecognizer

AppKit Touch Bar Support UIKit

NSPressGestureRecognizer UIPressGestureRecognizer

NSPanGestureRecognizer UIPanGestureRecognizer

NSClickGestureRecognizer UITapGestureRecognizer

NSMagnificationGestureRecognizer UIMagnificationGestureRecognizer

recognizer.allowedTouchTypes = .direct

Page 171: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Press-and-Hold Popovers

NSPopoverTouchBarItem.pressAndHoldTouchBar

Simple list-like UI

NSResponder.touchesBegan(with:) on enter

NSResponder.touchesCancelled(with:) on exit

No gesture recognizers

Page 172: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Press-and-Hold Popovers

NSPopoverTouchBarItem.pressAndHoldTouchBar

Simple list-like UI

NSResponder.touchesBegan(with:) on enter

NSResponder.touchesCancelled(with:) on exit

No gesture recognizers

Page 173: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Press-and-Hold Popovers

NSPopoverTouchBarItem.pressAndHoldTouchBar

Simple list-like UI

NSResponder.touchesBegan(with:) on enter

NSResponder.touchesCancelled(with:) on exit

No gesture recognizers

Page 174: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Event Modality

Touch Bar is a responsive input device

No modal interactions • Event tracking loops • Drag and Drop • Touch Bar interaction

Page 175: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Multiple Input Devices

Multi-Touch on Touch Bar

Keyboard Input

Cursor Input

Page 176: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Multiple Input Devices Multi-Touch

Page 177: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Multiple Input Devices Multi-Touch

Page 178: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Multiple Input Devices Multi-Touch

Page 179: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Multiple Input Devices

Page 180: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Event Handling •Styling and Appearance •Layout •Animation

Page 181: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286
Page 182: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286
Page 183: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286
Page 184: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286
Page 185: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286
Page 186: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286
Page 187: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

System Colors

Label SecondaryLabel

Control ControlBackground

TertiaryLabel

QuaternaryLabel

Control Text Disabled Control Text

Page 188: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

System Colors NEW

systemOrange

systemRed

systemPurple

Label SecondaryLabel

Control ControlBackground

TertiaryLabel

QuaternaryLabel

Control Text Disabled Control Text

systemBlue

systemGreen

systemYellow

systemPink

systemBrown

Page 189: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Drawing with System Colors

Page 190: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Drawing with System Colors

class LayerBasedDrawingView : NSView {

}

Page 191: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Drawing with System Colors

class LayerBasedDrawingView : NSView {

required override init(frame: NSRect) {

super.init(frame: frame)

aLayer.backgroundColor = NSColor.controlColor.cgColor

}

var bezelColor = NSColor.controlColor {

didSet {

aLayer.backgroundColor = bezelColor.cgColor

}

}

}

Page 192: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Drawing with System Colors

class LayerBasedDrawingView : NSView {

}

Page 193: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Drawing with System Colors

class LayerBasedDrawingView : NSView {

override func updateLayer() {

super.updateLayer()

aLayer.backgroundColor = NSColor.controlColor.cgColor

}

}

Page 194: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Drawing with System Colors

class LayerBasedDrawingView : NSView {

override func updateLayer() {

super.updateLayer()

aLayer.backgroundColor = bezelColor.cgColor

}

var bezelColor: NSColor = .controlColor {

didSet {

needsDisplay = true

}

}

}

Page 195: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Drawing with System Colors

class LayerBasedDrawingView : NSView {

override func updateLayer() {

super.updateLayer()

aLayer.backgroundColor = bezelColor.cgColor

}

var bezelColor: NSColor = .controlColor {

didSet {

needsDisplay = true

}

}

}

Page 196: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Drawing with System Colors

class LayerBasedDrawingView : NSView {

override func updateLayer() {

super.updateLayer()

aLayer.backgroundColor = bezelColor.cgColor

}

var bezelColor: NSColor = .controlColor {

didSet {

needsDisplay = true

}

}

}

Page 197: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Drawing with System Colors

class DrawRectBasedView : NSView {

override func draw(_ rect: NSRect) {

bezelColor.set()

rect.fill()

}

var bezelColor: NSColor = .controlColor {

didSet {

needsDisplay = true

}

}

}

Page 198: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

// Custom Drawing with System Colors

class DrawRectBasedView : NSView {

override func draw(_ rect: NSRect) {

bezelColor.set()

rect.fill()

}

var bezelColor: NSColor = .controlColor {

didSet {

needsDisplay = true

}

}

}

Page 199: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Control Tinting

button.bezelColor = .systemYellow segmentedControl.selectedSegmentBezelColor = .systemPurple slider.trackFillColor = .systemGreen

Page 200: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Default Button

button.bezelColor = .systemBlue

Page 201: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Default Button

button.keyEquivalent = "\r"

Page 202: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Default Button

button.keyEquivalent = "\r"

Page 203: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Esc Key Replacement

touchBar.escapeKeyReplacementItemIdentifier = doneButtonItemIdentifier

Modal contexts

Undoable action

Automatic metrics

Page 204: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Esc Key Replacement

touchBar.escapeKeyReplacementItemIdentifier = doneButtonItemIdentifier

Modal contexts

Undoable action

Automatic metrics

Page 205: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Font

Page 206: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Font

let font = NSFont.systemFont(ofSize: 0)

let boldFont = NSFont.systemFont(ofSize: 0, weight: .bold)

Page 207: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Font

let font = NSFont.systemFont(ofSize: 0)

let boldFont = NSFont.systemFont(ofSize: 0, weight: .bold)

Page 208: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Font

let font = NSFont.systemFont(ofSize: 0)

let boldFont = NSFont.systemFont(ofSize: 0, weight: .bold)

Page 209: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Font

let font = NSFont.systemFont(ofSize: 0)

let boldFont = NSFont.systemFont(ofSize: 0, weight: .bold)

let font = NSFont.monospacedDigitSystemFont(ofSize: 0, weight: .regular)

Page 210: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Font

Introducing the New System Fonts WWDC 2015

Typography and Font WWDC 2016

let font = NSFont.systemFont(ofSize: 0)

let boldFont = NSFont.systemFont(ofSize: 0, weight: .bold)

let font = NSFont.monospacedDigitSystemFont(ofSize: 0, weight: .regular)

Page 211: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

2x assets

Designed for Touch Bar

Template rendering

Images

Page 212: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Images

Like

Page 213: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Images

Like

Page 214: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Images

Like

Page 215: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Images

Like

Page 216: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Images

Like

Page 217: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Images

Like

Page 218: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286
Page 219: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Event Handling •Styling and Appearance •Layout •Animation

Page 220: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

NSTouchBar Item Layout

Flexible Spaces

Principal Item

Standard Item Layout

Page 221: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Sizing Fixed Size Controls

override var intrinsicContentSize: NSSize { let buttonWidth = // calculate from text + padding return NSSize(width: buttonWidth, height: 30) }

Page 222: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Sizing Fixed Size Controls

override var intrinsicContentSize: NSSize { let buttonWidth = // calculate from text + padding return NSSize(width: buttonWidth, height: 30) }

Page 223: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Sizing Fixed Size Controls

override var intrinsicContentSize: NSSize { let buttonWidth = // calculate from text + padding return NSSize(width: buttonWidth, height: 30) }

invalidateIntrinsicContentSize()

Page 224: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Sizing Fixed Size Controls

let widthConstraint = widthAnchor.constraint(equalToConstant: 72)

widthConstraint.constant = newWidth

Page 225: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Sizing Fixed Size Controls

let widthConstraint = widthAnchor.constraint(equalToConstant: 72)

widthConstraint.constant = newWidth

Page 226: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Sizing Flexible Controls

override var intrinsicContentSize: NSSize { return NSSize(width: NSView.noIntrinsicMetric, height: 72)}

Page 227: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Sizing Flexible Controls

override var intrinsicContentSize: NSSize { return NSSize(width: NSView.noIntrinsicMetric, height: 72)}

Page 228: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Sizing Flexible Controls

override var intrinsicContentSize: NSSize { return NSSize(width: NSView.noIntrinsicMetric, height: 72)}

sliderItem.slider.widthAnchor.constraint(lessThanOrEqualToConstant: 300).isActive = truesliderItem.slider.widthAnchor.constraint(greaterThanOrEqualToConstant: 150).isActive = true

Page 229: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Sizing Flexible Controls

override var intrinsicContentSize: NSSize { return NSSize(width: NSView.noIntrinsicMetric, height: 72)}

sliderItem.slider.widthAnchor.constraint(lessThanOrEqualToConstant: 300).isActive = truesliderItem.slider.widthAnchor.constraint(greaterThanOrEqualToConstant: 150).isActive = true

Page 230: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Sizing Flexible Controls

override var intrinsicContentSize: NSSize { return NSSize(width: NSView.noIntrinsicMetric, height: 72)}

sliderItem.slider.widthAnchor.constraint(lessThanOrEqualToConstant: 300).isActive = truesliderItem.slider.widthAnchor.constraint(greaterThanOrEqualToConstant: 150).isActive = true

Page 231: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Equal Sizing NEW

extension NSGroupTouchBarItem { var prefersEqualWidths: Bool

}

User customization Localization

Page 232: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Visibility Priority

Page 233: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Visibility Priority

Page 234: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Visibility Priority

bookmarkItem.visibilityPriority = .low

Page 235: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Visibility Priority

bookmarkItem.visibilityPriority = .low

Page 236: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Compression Behavior NEW

Page 237: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Compression Behavior NEW

centerGroup.prioritizedCompressionOptions = [.hideImages]

Page 238: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Compression Behavior NEW

centerGroup.prioritizedCompressionOptions = [.hideImages]

Page 239: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Compression Behavior NEW

centerGroup.prioritizedCompressionOptions = [.hideText]

centerGroup.prioritizedCompressionOptions = [.hideImages]

Page 240: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Compression Behavior NEW

centerGroup.prioritizedCompressionOptions = [.hideText]

centerGroup.prioritizedCompressionOptions = [.hideImages]

Page 241: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Container Views in Touch Bar

NSStackView

NSScrollView

NSScrubber

NSCollectionView

Choosing the Right Cocoa Container View Grand Ballroom A Wednesday 3:10PM

Page 242: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Container Views in Touch Bar

NSScrubber

NSCollectionView

NSStackView

Page 243: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Container Views in Touch Bar

NSScrubber

NSCollectionView

NSStackView

Page 244: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Container Views in Touch Bar

NSScrubber

NSCollectionView

NSStackView

Page 245: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Container Views in Touch Bar

NSScrubber

NSCollectionView

NSStackView

Page 246: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Container Views in Touch Bar

NSScrubber

NSCollectionView

NSStackView

Page 247: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Container Views in Touch Bar

NSScrubber

NSCollectionView

NSStackView

Page 248: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

•Event Handling •Styling and Appearance •Layout •Animation

Page 249: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Animation

Input device, not display

Don’t distract

Relative to user interaction

Interruptible

Page 250: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Animation

Input device, not display

Don’t distract

Relative to user interaction

Interruptible

Page 251: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Size Animation Constant Size

let widthConstraint = widthAnchor.constraint(equalToConstant: 72)

// on tap recognitionwidthConstraint.constant = newWidth

Page 252: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Size Animation Constant Size

let widthConstraint = widthAnchor.constraint(equalToConstant: 72)

// on tap recognitionwidthConstraint.constant = newWidth

Page 253: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Size Animation Constant Size

let widthConstraint = widthAnchor.constraint(equalToConstant: 72)

// on tap recognitionwidthConstraint.animator().constant = newWidth

Page 254: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Size Animation Constant Size

override var intrinsicContentSize: NSSize {

return NSSize(width: isActive ? 152 : 72, height: 30)

}

isActive = !isActive invalidateIntrinsicContentSize()

Page 255: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Size Animation Constant Size

override var intrinsicContentSize: NSSize {

return NSSize(width: isActive ? 152 : 72, height: 30)

}

isActive = !isActive invalidateIntrinsicContentSize()

Page 256: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Size Animation Constant Size

override var intrinsicContentSize: NSSize {

return NSSize(width: isActive ? 152 : 72, height: 30)

}

NSAnimationContext.runAnimationGroup({ context in

context.allowsImplicitAnimation = true window?.layoutIfNeeded() })

isActive = !isActive invalidateIntrinsicContentSize()

Page 257: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Item Size Animation Constant Size

override var intrinsicContentSize: NSSize {

return NSSize(width: isActive ? 152 : 72, height: 30)

}

NSAnimationContext.runAnimationGroup({ context in

context.allowsImplicitAnimation = true window?.layoutIfNeeded() })

isActive = !isActive invalidateIntrinsicContentSize()

Page 258: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

override var intrinsicContentSize: NSSize {

return NSSize(width: isActive ? NSView.noIntrinsicMetric : 72, height: 30)

}

NSAnimationContext.runAnimationGroup({ context in isActive = !isActive invalidateIntrinsicContentSize() context.allowsImplicitAnimation = true window?.layoutIfNeeded() })

Item Size Animation Flexibility

Page 259: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

override var intrinsicContentSize: NSSize {

return NSSize(width: isActive ? NSView.noIntrinsicMetric : 72, height: 30)

}

NSAnimationContext.runAnimationGroup({ context in isActive = !isActive invalidateIntrinsicContentSize() context.allowsImplicitAnimation = true window?.layoutIfNeeded() })

Item Size Animation Flexibility

Page 260: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

override var intrinsicContentSize: NSSize {

return NSSize(width: isActive ? NSView.noIntrinsicMetric : 72, height: 30)

}

NSAnimationContext.runAnimationGroup({ context in isActive = !isActive invalidateIntrinsicContentSize() context.allowsImplicitAnimation = true window?.layoutIfNeeded() })

Item Size Animation Flexibility

Page 261: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286
Page 262: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

class AccordionView : NSView {

var isActive: Bool {

didSet {

invalidateIntrinsicContentSize()

}

}

override var intrinsicContentSize: NSSize {

return NSSize(width: isActive ? NSView.noIntrinsicMetric : 72, height: 30)

}

// drawing, slider event handling ...

}

Page 263: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

class AccordionView : NSView {

var isActive: Bool {

didSet {

invalidateIntrinsicContentSize()

}

}

override var intrinsicContentSize: NSSize {

return NSSize(width: isActive ? NSView.noIntrinsicMetric : 72, height: 30)

}

// drawing, slider event handling ...

}

false

Page 264: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

class AccordionView : NSView {

var isActive: Bool {

didSet {

invalidateIntrinsicContentSize()

}

}

override var intrinsicContentSize: NSSize {

return NSSize(width: isActive ? NSView.noIntrinsicMetric : 72, height: 30)

}

// drawing, slider event handling ...

}

true

Page 265: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

var activeAccordionView: AccordionView

func handlePress(_ recognizer: NSPressGestureRecognizer) { let oldActiveAccordionView = activeAccordionView let newActiveAccordionView = recognizer.view as! AccordionView

NSAnimationContext.runAnimationGroup({ context in

oldActiveAccordionView.isActive = false

newActiveAccordionView.isActive = true

context.allowsImplicitAnimation = true

activeAccordionView.window?.layoutIfNeeded()

})

activeAccordionView = newActiveAccordionView

}

Page 266: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

var activeAccordionView: AccordionView

func handlePress(_ recognizer: NSPressGestureRecognizer) { let oldActiveAccordionView = activeAccordionView let newActiveAccordionView = recognizer.view as! AccordionView

NSAnimationContext.runAnimationGroup({ context in

oldActiveAccordionView.isActive = false

newActiveAccordionView.isActive = true

context.allowsImplicitAnimation = true

activeAccordionView.window?.layoutIfNeeded()

})

activeAccordionView = newActiveAccordionView

}

Page 267: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

var activeAccordionView: AccordionView

func handlePress(_ recognizer: NSPressGestureRecognizer) { let oldActiveAccordionView = activeAccordionView let newActiveAccordionView = recognizer.view as! AccordionView

NSAnimationContext.runAnimationGroup({ context in

oldActiveAccordionView.isActive = false

newActiveAccordionView.isActive = true

context.allowsImplicitAnimation = true

activeAccordionView.window?.layoutIfNeeded()

})

activeAccordionView = newActiveAccordionView

}

Page 268: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

var activeAccordionView: AccordionView

func handlePress(_ recognizer: NSPressGestureRecognizer) { let oldActiveAccordionView = activeAccordionView let newActiveAccordionView = recognizer.view as! AccordionView

NSAnimationContext.runAnimationGroup({ context in

oldActiveAccordionView.isActive = false

newActiveAccordionView.isActive = true

context.allowsImplicitAnimation = true

activeAccordionView.window?.layoutIfNeeded()

})

activeAccordionView = newActiveAccordionView

}

Page 269: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

var activeAccordionView: AccordionView

func handlePress(_ recognizer: NSPressGestureRecognizer) { let oldActiveAccordionView = activeAccordionView let newActiveAccordionView = recognizer.view as! AccordionView

NSAnimationContext.runAnimationGroup({ context in

oldActiveAccordionView.isActive = false

newActiveAccordionView.isActive = true

context.allowsImplicitAnimation = true

activeAccordionView.window?.layoutIfNeeded()

})

activeAccordionView = newActiveAccordionView

}

Page 270: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

var activeAccordionView: AccordionView

func handlePress(_ recognizer: NSPressGestureRecognizer) { let oldActiveAccordionView = activeAccordionView let newActiveAccordionView = recognizer.view as! AccordionView

NSAnimationContext.runAnimationGroup({ context in

oldActiveAccordionView.isActive = false

newActiveAccordionView.isActive = true

context.allowsImplicitAnimation = true

activeAccordionView.window?.layoutIfNeeded()

})

activeAccordionView = newActiveAccordionView

}

Page 271: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

var activeAccordionView: AccordionView

func handlePress(_ recognizer: NSPressGestureRecognizer) { let oldActiveAccordionView = activeAccordionView let newActiveAccordionView = recognizer.view as! AccordionView

NSAnimationContext.runAnimationGroup({ context in

oldActiveAccordionView.isActive = false

newActiveAccordionView.isActive = true

context.allowsImplicitAnimation = true

activeAccordionView.window?.layoutIfNeeded()

})

activeAccordionView = newActiveAccordionView

}

Page 272: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

var activeAccordionView: AccordionView

func handlePress(_ recognizer: NSPressGestureRecognizer) { let oldActiveAccordionView = activeAccordionView let newActiveAccordionView = recognizer.view as! AccordionView

NSAnimationContext.runAnimationGroup({ context in

oldActiveAccordionView.isActive = false

newActiveAccordionView.isActive = true

context.allowsImplicitAnimation = true

activeAccordionView.window?.layoutIfNeeded()

})

activeAccordionView = newActiveAccordionView

}

Page 273: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

var activeAccordionView: AccordionView

func handlePress(_ recognizer: NSPressGestureRecognizer) { let oldActiveAccordionView = activeAccordionView let newActiveAccordionView = recognizer.view as! AccordionView

NSAnimationContext.runAnimationGroup({ context in

oldActiveAccordionView.isActive = false

newActiveAccordionView.isActive = true

context.allowsImplicitAnimation = true

activeAccordionView.window?.layoutIfNeeded()

})

activeAccordionView = newActiveAccordionView

}

Page 274: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Within-Item Animation Layout

Constraints or layout() override

No extra work!

Page 275: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Within-Item Animation Button Content

NEW

button1.title = "Rotate" button1.image = NSImage(named: .touchBarRotateRightTemplate) button2.bezelColor = .systemRed button3.imagePosition = .imageLeading

Bird

Page 276: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Within-Item Animation Button Content

NEW

button1.title = "Rotate" button1.image = NSImage(named: .touchBarRotateRightTemplate) button2.bezelColor = .systemRed button3.imagePosition = .imageLeading

Bird

Page 277: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Within-Item Animation Button Content

NEW

button1.animator().title = "Rotate" button1.animator().image = NSImage(named: .touchBarRotateRightTemplate) button2.animator().bezelColor = .systemRed button3.animator().imagePosition = .imageLeading

Bird

Page 278: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Within-Item Animation Button Content

NEW

button1.animator().title = "Rotate" button1.animator().image = NSImage(named: .touchBarRotateRightTemplate) button2.animator().bezelColor = .systemRed button3.animator().imagePosition = .imageLeading

Bird

Page 279: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Within-Item Animation Button Content

NEW

NSAnimationContext.runAnimationGroup({ context in

button2.animator().imagePosition = .imageLeading

context.allowsImplicitAnimation = true

button2.window?.layoutIfNeeded()

})

button1.animator().title = "Rotate" button1.animator().image = NSImage(named: .touchBarRotateRightTemplate) button2.animator().bezelColor = .systemRed button3.animator().imagePosition = .imageLeading

Bird

Page 280: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Animator proxy

CAAnimation

layout() override and allowsImplicitAnimation

Within-Item Animation Custom

Best Practices for Cocoa Animation WWDC 2013

Page 281: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Animator proxy

CAAnimation

layout() override and allowsImplicitAnimation

Within-Item Animation Custom

Best Practices for Cocoa Animation WWDC 2013

Page 282: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Summary

Customize text view bar content

Use and customize NSScrubber

Create unique Touch Bar interactions

Page 283: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

More Informationhttps://developer.apple.com/wwdc17/222

Page 284: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Related Sessions

Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AM

Choosing the Right Cocoa Container View Grand Ballroom B Wednesday 3:10PM

Building Visually Rich User Experiences Hall 2 Thursday 5:10PM

Best Practices for Cocoa Animation WWDC 2013

Introducing the New System Fonts WWDC 2015

Typography and Font WWDC 2016

Page 285: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286

Labs

Cocoa Touch Bar Lab Technology Lab C Thu 9:00AM–11:00AM

Cocoa Lab Technology Lab B Fri 1:50PM–3:20PM

Page 286: •Advanced Touch Bar - Apple Inc....Touch Bar Fundamentals Grand Ballroom A Wednesday 10:00AMFile Size: 4MBPage Count: 286