Leszek Zarna
Leszek Zarna

Reputation: 3317

Is there some iOS library emulating 3D touch peek and pop on older devices?

It would be great to have library that both:

Advantages:

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

Upvotes: -3

Views: 994

Answers (4)

Dheeraj
Dheeraj

Reputation: 92

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.

Upvotes: 0

huong
huong

Reputation: 4564

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

Upvotes: 1

byJeevan
byJeevan

Reputation: 3838

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

Upvotes: 0

Gordon Childs
Gordon Childs

Reputation: 36074

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.

Upvotes: 1

Related Questions