Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Amazing Powers and Mesmerizing Secrets of 3...

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/

Alexis Gallagher

November 05, 2015
Tweet

More Decks by Alexis Gallagher

Other Decks in Technology

Transcript

  1. 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. 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. 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 } }
  4. 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]
  5. 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:
  6. 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
  7. 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
  8. 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)
  9. 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
  10. tap press Hint press press Peek Pop Quick Actions swipe

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

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

    Navigation: UIViewControllerPreviewingDelegate .previewingContext(_:commitViewController:) -> Void Provides Peek Quick Actions: UIViewController.previewActionItems() -> [UIPreviewActionItem]
  13. Force Properties Designed for: adventure! • No design direction &

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

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

    own gesture recognizers and controls • SqueezeButton, ForceSqueezeGestureRecognizer, PeekPopGestureRecognizer, etc..
  17. Force Properties Precision & Accuracy • Can access a touch's

    force, radius, and radius error • But what is the reported resolution of the force sensor?
  18. 0.2 0.4 0.6 0.8 1.0 force maxForce 0 20 40

    60 80 100 count Force values (n ≈ 2000)
  19. 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?
  20. 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
  21. 1 2 3 4 5 6 CGFloat 0 1 2

    3 4 Newtons physicalforce vs UITouch.force
  22. 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
  23. • 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.
  24. Resources • Apple's "Adopting 3D Touch on iPhone" and sample

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