Simulate force touch / 3D touch on iPhone 6S or iP

2019-01-04 21:47发布

I am trying to simulate a force touch using Xcode 7 GM on the iPhone 6S or iPhone 6S Plus simulator. In particular, I am trying to simulate the force touch on the icon of the test app which is implementing Application Shortcuts.

Let me know if there is a solution to simulate this, I tried the long press which the Watch simulator uses to simulate force touch, didn't work since the iPhone captures it as a long press gesture.

Update: I downloaded the ViewControllerPreview Sample code from Apple. Running their sample application I see that the simulator, although an iPhone 6s, does not support for 3D / force touch feature. I am still unsure if it would support the feature if I were to be using a macbook with a force touch enabled trackpad.

enter image description here

EDIT: Can someone with a macbook that has a force touch trackpad attempt to use the force touch on the trackpad to simulate 3D touch on the iPhone 6s or 6s Plus simulator? My theory is that you can maybe use the force touch trackpad on the new MacBooks to simulate the 3D touch on new iPhone simulators. Add a comment noting the results if you try it and I can update the post.

EDIT2: It seems that Force Touch trackpads on the newer model macbook pros do not help.

10条回答
神经病院院长
2楼-- · 2019-01-04 22:06

With Xcode 7.3 you can test the 3D touch feature in simulator but with only one constraint. (Xcode7.3 release notes reference)

The machine(macbook/mac with trackpad) your are developing should have 3D touch capability.

You can find it under iOS simulator Hardware menu.

Comments from Pavel Alexeev: Be sure to enable “Force Click and haptic feedback” in System Preferences → Trackpad

enter image description here

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-04 22:23

For the "Home Screen Quick Actions" touch I made the following:

  • created an object of UIMutableApplicationShortcutItem

  • put it into launchOptions to UIApplicationLaunchOptionsShortcutItemKey

  • and thats it

It looks like user did the 3d touch on the app icon.

    let shortcut = UIMutableApplicationShortcutItem(type: ShortcutIdentifier.Third.type,
        localizedTitle: "Title",
        localizedSubtitle: "Subtitle",
        icon: UIApplicationShortcutIcon(type: .Play), userInfo: [
        AppDelegate.applicationShortcutUserInfoIconKey: UIApplicationShortcutIconType.Play.rawValue
        ]
    )

    let launchOption = [
        "UIApplicationLaunchOptionsShortcutItemKey" : shortcut
    ]

    launchOptions = launchOption

(application:didFinishLaunchingWithOptions:)

查看更多
戒情不戒烟
4楼-- · 2019-01-04 22:24

It says here! at the bottom of the page....

Development Environment

Xcode 7 supports 3D Touch development. All the debugging features of Xcode are available for implementing the new features.

Keep the following in mind:

With Xcode 7.0 you must develop on a device that supports 3D Touch. Simulator in Xcode 7.0 does not support 3D Touch.

With Xcode 7.0 you must implement your peek and pop view controllers in code. Interface Builder in Xcode 7.0 does not provide graphical support for configuring view controllers or transitions for 3D Touch.

Be sure to test your app with 3D Touch both enabled and disabled, ensuring that all features are available to all users. On a 3D Touch device, you can disable 3D Touch in Settings > General > Accessibility > 3D Touch

So unfortunately it looks like we need to get our hands on the actual devices to do it. :-(

EDIT.....

As of Xcode 7.3 there is a way to do this if your MacBook's trackpad supports force touch. See answer by @iPrabu.

查看更多
Lonely孤独者°
5楼-- · 2019-01-04 22:25

Force pressure in iOS (eg: Peek & Pop) is not exposed through Xcode 7.0 nor Xcode 7.1 Beta's Simulator. The pressure touch options are only relevant for watchOS devices in those versions of Simulator. If you have the Xcode 7.1 beta, you'll notice that the menu option is actually disabled.

With Xcode 7.3 and the iOS 9.3 and later simulator runtimes, you can test peek/pop functionality using a force touch trackpad.

查看更多
聊天终结者
6楼-- · 2019-01-04 22:27

You can enable 3D Touch in simulator. Thanks to this library.

  • After adding it Using a combination of the command, control, and shift keys 3D Touch can be enabled.

  • Don't forget to add library in Debug environment only. Exclude it from Release environment.

查看更多
闹够了就滚
7楼-- · 2019-01-04 22:27

There's a bit of code here that allows you to test 3D Touch peek & pop in the simulator. Bear in mind this is code for iOS 9.0, and some of the internal/private methods have changed in 9.1 so you'll need to make a few minor changes (Hint: the word 'Position' changed to 'Location' in one of the method names).

https://gist.github.com/nickfrey/07e2c6d8d2e5444fb91d

Both this and https://github.com/DeskConnect/SBShortcutMenuSimulator mentioned in other answers allow you to test for 3D Touch without an actual device fairly competently.

查看更多
登录 后发表回答