Slide 1

Slide 1 text

The Amazing Powers & Mesmerizing Secrets of 3D Touch @alexisgallagher

Slide 2

Slide 2 text

First New Input Method • iPhone 3G : GPS • iPhone 3GS : Digital Compass • iPhone 4 : Front Camera • iPhone 5S : Touch ID • iPhone 6 : Barometer • iPhone 6s : 3D Touch !"

Slide 3

Slide 3 text

Three new APIs

Slide 4

Slide 4 text

Three new APIs 1.Home Screen Quick Actions 2.Peek and Pop 3.Force Properties !

Slide 5

Slide 5 text

1. Home Screen Quick Actions

Slide 6

Slide 6 text

Quick Actions Designed for: purposeful launch • Shortcut to launch an app with an action • Static actions (e.g., "New Message") • Dynamic actions (e.g., "Johnny Appleseed")

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Configuring Quick Actions Your app provides UIApplicationShortcutItems: class UIApplicationShortcutItem { // app-specific action identifier & payload var type: String { get } var userInfo: [String : NSSecureCoding]? { get } // title, maybe subtitle & icon var localizedTitle: String { get } var localizedSubtitle: String? { get } var icon: UIApplicationShortcutIcon? { get } }

Slide 9

Slide 9 text

Providing Quick Actions Static actions go on the Info.plist:

Slide 10

Slide 10 text

Providing Quick Actions Dynamic actions go in the UIApplication object: let quickAction = UIMutableApplicationShortcutItem(type: "mytype", localizedTitle: "Play", localizedSubtitle: nil, icon: UIApplicationShortcutIcon(type: .Play), userInfo: nil) UIApplication.sharedApplication().shortcutItems = [quickAction]

Slide 11

Slide 11 text

Responding to Quick Actions On launch, via app delegate launch methods: func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // If a shortcut was launched, display its information and take the appropriate action if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem where shortcutItem.type == "myType" { // do something associated with "myType" shortcut and its userInfo data payload } // ... return true } On activation or if launch methods returned true, via the new method, performActionForShortcut:

Slide 12

Slide 12 text

Home Screen Quick Actions Key Points • Fixed format: title, icon, maybe subtitle • Configured statically in Info.plist, or dynamically at runtime • Passed to the app delegate launch methods, and/ or a dedicated protocol method

Slide 13

Slide 13 text

Home Screen Quick Actions Gotchas • Constraints on icon imagery (system-provided, static template, or contact photo) • When to update dynamic items (Accounting for all states produced by app lifecycle, app update, etc..) • Confusing API for app delegate launch methods

Slide 14

Slide 14 text

2. Peek and Pop

Slide 15

Slide 15 text

Peek and Pop • Pressing triggers preview of tappable content • Pressing triggers stages: 1.Hint (blur background) 2.Peek (content preview) 3.Pop (navigate as if tapped)

Slide 16

Slide 16 text

press Hint press press Peek Pop

Slide 17

Slide 17 text

tap press Hint press press Peek Pop

Slide 18

Slide 18 text

tap release press Hint press press Peek Pop

Slide 19

Slide 19 text

tap press Hint press press Peek Pop Quick Actions swipe

Slide 20

Slide 20 text

Peek and Pop Designed for: faster navigation • Pop navigates just like a tap • Peek previews content reachable by tap • Peek Quick Action is a shortcut to content beyond a tap

Slide 21

Slide 21 text

tap press Hint press press Peek Pop Quick Actions swipe

Slide 22

Slide 22 text

tap press Hint press press Peek Pop Quick Actions swipe DestinationViewController PreviewViewController previewActionItems()

Slide 23

Slide 23 text

tap press Hint press press Peek Pop Quick Actions swipe DestinationViewController PreviewViewController previewActionItems() UIViewController registerForPreviewingWithDelegate(_:sourceView:) UIViewControllerPreviewDelegate previewingContext(_:viewControllerForLocation:) previewingContext(_:commitViewController:)

Slide 24

Slide 24 text

Provides Peek View Controller: UIViewControllerPreviewingDelegate .previewingContext(_:viewControllerForLocation:) -> UIViewController? Performs Pop Navigation: UIViewControllerPreviewingDelegate .previewingContext(_:commitViewController:) -> Void Provides Peek Quick Actions: UIViewController.previewActionItems() -> [UIPreviewActionItem]

Slide 25

Slide 25 text

3. Force Properties !

Slide 26

Slide 26 text

Force Properties

Slide 27

Slide 27 text

Force Properties Designed for: adventure! • No design direction & few examples from Apple • Extremely capable hardware

Slide 28

Slide 28 text

Force Properties Adopting the API • UITouch.force : CGFloat • UITouch.maximumPossibleForce • UITraitCollection.forceTouchCapability • UIResponder.estimatedPropertiesUpdated(_:)

Slide 29

Slide 29 text

3D Touch Gesture Recognizers class ALGSqueezeGestureRecognizer: UIGestureRecognizer { var squeezeThreshhold:CGFloat = 0.5 override func touchesMoved(touches:Set, withEvent:UIEvent) { super.touchesMoved(touches, withEvent: event) if touches.count == 1 && UIScreen.mainScreen().traitCollection.forceTouchCapability == .Available { let normalizedForce = touches.first!.force / touches.first!.maximumPossibleForce if normalizedForce >= self.squeezeThreshhold { self.state = .Recognized } } else { self.state = .Failed } } // etc. at }

Slide 30

Slide 30 text

Force Properties Gotchas • Do check UITraitCollection.forceTouchCapability • Define your own gesture recognizers and controls • SqueezeButton, ForceSqueezeGestureRecognizer, PeekPopGestureRecognizer, etc..

Slide 31

Slide 31 text

Force Properties Precision & Accuracy • Can access a touch's force, radius, and radius error • But what is the reported resolution of the force sensor?

Slide 32

Slide 32 text

0.2 0.4 0.6 0.8 1.0 force maxForce 0 20 40 60 80 100 count Force values (n ≈ 2000)

Slide 33

Slide 33 text

Force Properties Precision • Reported force resolution is very precise (600 possible values, or ≈0.2% resolution) • Much more precise than UITouch.radius information • But is it just noise? How accurate?

Slide 34

Slide 34 text

My Quest For a Touch Pedestal • UIKit API: all force detection requires capacitive touch detection • To measure force (e.g., to weigh an object) we need a weightless finger to activate touch, a touch pedestal • Many things don't work

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

uh, just how does capacitive touch work anyway?

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

1 2 3 4 5 6 CGFloat 0 1 2 3 4 Newtons physicalforce vs UITouch.force

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

Force Properties • UITouch.force seems to measure actual force • UIKit's minimum reported force values seem physically meaningful (< 5 grams, e.g., 3 playing cards) • maximumPossibleForce is around 0.5 kg

Slide 63

Slide 63 text

Force Properties Let a thousand user experiences bloom! !"#$%

Slide 64

Slide 64 text

• Drawing • Music • Game controls • Text selection (press to expand selection) • Whacky easter eggs (press to "shatter", to "wobble") • Measure the physical world: • postal scale, breath strength, etc.

Slide 65

Slide 65 text

But… is this just right click?

Slide 66

Slide 66 text

Resources • Apple's "Adopting 3D Touch on iPhone" and sample code • Tools and demos: https://github.com/algal/TouchVisualizer

Slide 67

Slide 67 text

The Amazing Powers & Mesmerizing Secrets of 3D Touch @alexisgallagher