The Amazing Powers and Mesmerizing Secrets of 3D Touch

The Amazing Powers and Mesmerizing Secrets of 3D Touch

A somewhat mad science experiment where I explore the 3D touch features of the iPhone 6s, by building a "touch pedestal." (Also, I explain the 3D Touch API introduced in iOS 9.)

PDF deck of the talk given at: https://realm.io/news/alexis-gallagher-3d-touch-swift/

4b71cdf53bc76edd1a2ab66c446954b5?s=128

Alexis Gallagher

November 05, 2015
Tweet

Transcript

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

  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 !"
  3. Three new APIs

  4. Three new APIs 1.Home Screen Quick Actions 2.Peek and Pop

    3.Force Properties !
  5. 1. Home Screen Quick Actions

  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")
  7. None
  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 } }
  9. Providing Quick Actions Static actions go on the Info.plist:

  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]
  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:
  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
  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
  14. 2. Peek and Pop

  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)
  16. press Hint press press Peek Pop

  17. tap press Hint press press Peek Pop

  18. tap release press Hint press press Peek Pop

  19. tap press Hint press press Peek Pop Quick Actions swipe

  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
  21. tap press Hint press press Peek Pop Quick Actions swipe

  22. tap press Hint press press Peek Pop Quick Actions swipe

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

    DestinationViewController PreviewViewController previewActionItems() UIViewController registerForPreviewingWithDelegate(_:sourceView:) UIViewControllerPreviewDelegate previewingContext(_:viewControllerForLocation:) previewingContext(_:commitViewController:)
  24. Provides Peek View Controller: UIViewControllerPreviewingDelegate .previewingContext(_:viewControllerForLocation:) -> UIViewController? Performs Pop

    Navigation: UIViewControllerPreviewingDelegate .previewingContext(_:commitViewController:) -> Void Provides Peek Quick Actions: UIViewController.previewActionItems() -> [UIPreviewActionItem]
  25. 3. Force Properties !

  26. Force Properties

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

    few examples from Apple • Extremely capable hardware
  28. Force Properties Adopting the API • UITouch.force : CGFloat •

    UITouch.maximumPossibleForce • UITraitCollection.forceTouchCapability • UIResponder.estimatedPropertiesUpdated(_:)
  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> }
  30. Force Properties Gotchas • Do check UITraitCollection.forceTouchCapability • Define your

    own gesture recognizers and controls • SqueezeButton, ForceSqueezeGestureRecognizer, PeekPopGestureRecognizer, etc..
  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?
  32. 0.2 0.4 0.6 0.8 1.0 force maxForce 0 20 40

    60 80 100 count Force values (n ≈ 2000)
  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?
  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
  35. None
  36. None
  37. None
  38. None
  39. None
  40. None
  41. None
  42. None
  43. None
  44. None
  45. None
  46. None
  47. None
  48. None
  49. uh, just how does capacitive touch work anyway?

  50. None
  51. None
  52. None
  53. None
  54. None
  55. None
  56. None
  57. None
  58. None
  59. None
  60. 1 2 3 4 5 6 CGFloat 0 1 2

    3 4 Newtons physicalforce vs UITouch.force
  61. None
  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
  63. Force Properties Let a thousand user experiences bloom! !"#$%

  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.
  65. But… is this just right click?

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

    code • Tools and demos: https://github.com/algal/TouchVisualizer
  67. The Amazing Powers & Mesmerizing Secrets of 3D Touch @alexisgallagher