0

It would be great to have library that both:

  • uses new 3D Touch api on iPhone 6s
  • on older devices emulates peek and pop with some gestures.

Advantages:

  • users of older devices could benefit from new interface possibilities
  • adoption of peek and pop would be faster - no need to wait years till everybody has newer model.
  • developers would not need to instantly buy new hardware to test 3D touch

Anybody knows if that is possible or knows code - please share with us.

Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
Leszek Zarna
  • 3,253
  • 26
  • 26

6 Answers6

1

You could perhaps emulate the behaviour by looking at the UITouch properties majorRadius and majorRadiusTolerance, available in iOS 8, which describe the approximate radius of the touch or "finger fatness".

This ought to be loosely correlated with pressure.

I'm not sure the properties change continuously / produce a stream of touchesMoved: callbacks, but it might be a start.

Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159
1

I have built a library to use as an alternative for devices without 3D Touch. My demo project also demonstrates how the project can support both types of devices. You can try it here: PeekView

The usage is pretty simple:

  • Add UILongPressGestureRecognizer to the view you want to peek (i.e table view cell, image, hypertext, etc.)
  • Create a UIViewController instance as the content of your peek view; then set your desired frame for the content view. It's recommended to leave a 15px padding for both left and right margin of your content view.
  • If you want to include preview actions, prepare an array containing title of the buttons and its preview style. Don't forget to prepare completion handlers for when each button is tapped.

Sample snippet:

PeekView.viewForController(
  parentViewController: self, 
  contentViewController: controller, 
  expectedContentViewFrame: frame, 
  fromGesture: gestureRecognizer, 
  shouldHideStatusBar: true, 
  withOptions: ["Option 1": .Destructive, "Option 2": .Default, "Option 3": .Selected], 
  completionHandler: { optionIndex in
                    switch optionIndex {
                    case 0:
                        print("Option 1 selected")
                    case 1:
                        print("Option 2 selected")
                    case 2:
                        print("Option 3 selected")
                    default:
                        break
                    }
                })

Preview:

Screenshot

huong
  • 4,534
  • 6
  • 33
  • 54
  • your library have issue for lower cell, if user long press cells at bottom and panned it , it gives jerk and content is misplaced at wrong location.(btw nice library needs improvement) – Mukesh Aug 02 '16 at 06:19
0

Here’s an open source project that provides a neat tweak for the iPhone simulator that allows you to simulate 3D touch within the iOS simulator called SBShortcutMenuSimulator.

SBShortcutMenuSimulator allows you to test usage of the UIApplicationShortcutItem API even without a device supporting 3D touch.

This screenshot from the readme shows a demonstration of an application shortcut menu in the simulator:

enter image description here

byJeevan
  • 3,728
  • 3
  • 37
  • 60
0

You can use this code to simulate peek and pop in the Simulator: https://gist.github.com/nickfrey/07e2c6d8d2e5444fb91d

Adjust the time of the second dispatch_after between peek and pop.

Of course, this is only suitable for debugging since it uses private API.

Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
0

This is what apple recommends:

"To ensure that all your users can access your app’s features, branch your code depending on whether 3D Touch is available. When it is available, take advantage of 3D Touch capabilities. When it is not available, provide alternatives such as by employing touch and hold, implemented with the UILongPressGestureRecognizer class."

Please check this link: https://goo.gl/4ez21g

Dheeraj
  • 92
  • 2
0

STPopupPreview: https://github.com/kevin0571/STPopupPreview
An easy-integrate library for peak preview on non 3D Touch devices.

Kevin
  • 1,147
  • 11
  • 21