The Astonishing Powers and Mesmerizing Secrets of 3D Touch

1fa9cb8c7997c8c4d3d251fb5e41f749?s=47 Realm
November 05, 2015

The Astonishing Powers and Mesmerizing Secrets of 3D Touch

Presented by Alexis Gallagher at the Swift Language User Group

1fa9cb8c7997c8c4d3d251fb5e41f749?s=128

Realm

November 05, 2015
Tweet

Transcript

  1. 2.

    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 !"
  2. 6.

    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")
  3. 7.
  4. 8.

    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 } }
  5. 10.

    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]
  6. 11.

    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:
  7. 12.

    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
  8. 13.

    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
  9. 15.

    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)
  10. 20.

    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
  11. 22.

    tap press Hint press press Peek Pop Quick Actions swipe

    DestinationViewController PreviewViewController previewActionItems()
  12. 23.

    tap press Hint press press Peek Pop Quick Actions swipe

    DestinationViewController PreviewViewController previewActionItems() UIViewController registerForPreviewingWithDelegate(_:sourceView:) UIViewControllerPreviewDelegate previewingContext(_:viewControllerForLocation:) previewingContext(_:commitViewController:)
  13. 24.

    Provides Peek View Controller: UIViewControllerPreviewingDelegate .previewingContext(_:viewControllerForLocation:) -> UIViewController? Performs Pop

    Navigation: UIViewControllerPreviewingDelegate .previewingContext(_:commitViewController:) -> Void Provides Peek Quick Actions: UIViewController.previewActionItems() -> [UIPreviewActionItem]
  14. 27.

    Force Properties Designed for: adventure! • No design direction &

    few examples from Apple • Extremely capable hardware
  15. 28.

    Force Properties Adopting the API • UITouch.force : CGFloat •

    UITouch.maximumPossibleForce • UITraitCollection.forceTouchCapability • UIResponder.estimatedPropertiesUpdated(_:)
  16. 29.

    3D Touch Gesture Recognizers class ALGSqueezeGestureRecognizer: UIGestureRecognizer { var squeezeThreshhold:CGFloat

    = 0.5 override func touchesMoved(touches:Set<UITouch>, 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 <https://github.com/algal/TouchVisualizer> }
  17. 30.

    Force Properties Gotchas • Do check UITraitCollection.forceTouchCapability • Define your

    own gesture recognizers and controls • SqueezeButton, ForceSqueezeGestureRecognizer, PeekPopGestureRecognizer, etc..
  18. 31.

    Force Properties Precision & Accuracy • Can access a touch's

    force, radius, and radius error • But what is the reported resolution of the force sensor?
  19. 32.

    0.2 0.4 0.6 0.8 1.0 force maxForce 0 20 40

    60 80 100 count Force values (n ≈ 2000)
  20. 33.

    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?
  21. 34.

    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
  22. 35.
  23. 36.
  24. 37.
  25. 38.
  26. 39.
  27. 40.
  28. 41.
  29. 42.
  30. 43.
  31. 44.
  32. 45.
  33. 46.
  34. 47.
  35. 48.
  36. 50.
  37. 51.
  38. 52.
  39. 53.
  40. 54.
  41. 55.
  42. 56.
  43. 57.
  44. 58.
  45. 59.
  46. 60.

    1 2 3 4 5 6 CGFloat 0 1 2

    3 4 Newtons physicalforce vs UITouch.force
  47. 61.
  48. 62.

    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
  49. 64.

    • 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.
  50. 66.

    Resources • Apple's "Adopting 3D Touch on iPhone" and sample

    code • Tools and demos: https://github.com/algal/TouchVisualizer