ios 在 iPhone 6S 或 iPhone 6S Plus 模拟器上模拟力触摸/3D 触摸
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32491188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simulate force touch / 3D touch on iPhone 6S or iPhone 6S Plus simulators
提问by Kris Gellci
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.
我正在尝试在 iPhone 6S 或 iPhone 6S Plus 模拟器上使用 Xcode 7 GM 模拟强制触摸。特别是,我试图模拟对实现应用程序快捷方式的测试应用程序图标的强制触摸。
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.
让我知道是否有模拟这个的解决方案,我尝试了 Watch 模拟器用来模拟强制触摸的长按,但没有工作,因为 iPhone 将其捕获为长按手势。
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.
更新:我从 Apple 下载了 ViewControllerPreview 示例代码。运行他们的示例应用程序,我看到模拟器虽然是 iPhone 6s,但不支持 3D/强制触摸功能。如果我要使用带有强制触控功能的触控板的 macbook,我仍然不确定它是否会支持该功能。
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.
编辑:拥有带有强制触摸触控板的 macbook 的人可以尝试使用触控板上的强制触控来模拟 iPhone 6s 或 6s Plus 模拟器上的 3D 触控吗?我的理论是,您可以使用新 MacBook 上的强制触摸触控板来模拟新 iPhone 模拟器上的 3D 触摸。如果您尝试,请添加注释并注明结果,我可以更新帖子。
EDIT2: It seems that Force Touch trackpads on the newer model macbook pros do not help.
EDIT2:似乎较新型号 macbook 专业版上的 Force Touch 触控板无济于事。
采纳答案by kaylanx
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
开发环境
Xcode 7 支持 3D Touch 开发。Xcode 的所有调试功能都可用于实现新功能。
请记住以下几点:
使用 Xcode 7.0,您必须在支持 3D Touch 的设备上进行开发。Xcode 7.0 中的模拟器不支持 3D Touch。
使用 Xcode 7.0,您必须在代码中实现您的 peek 和 pop 视图控制器。Xcode 7.0 中的 Interface Builder 不为配置视图控制器或 3D Touch 转换提供图形支持。
请务必在启用和禁用 3D Touch 的情况下测试您的应用,确保所有功能都可供所有用户使用。在 3D Touch 设备上,您可以在“设置”>“通用”>“辅助功能”>“3D Touch”中禁用 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.
从 Xcode 7.3 开始,如果您的 MacBook 的触控板支持强制触摸,则有一种方法可以做到这一点。请参阅@iPrabu 的回答。
回答by Nicolas S
For those that are developing Quick Actions (App Shortcuts) you can use this script that enables you to simulate a deep press on an app on the simulator.
对于那些正在开发快速操作(应用程序快捷方式)的人,您可以使用此脚本来模拟在模拟器上的应用程序上的深度按压。
https://github.com/DeskConnect/SBShortcutMenuSimulator
https://github.com/DeskConnect/SBShortcutMenuSimulator
For those that are looking at how to add the actions on the first place, there are two options, Static and Dynamic. You can set only 4 options, it will first show all Static ones, and if there's space, show Dynamic ones.
对于那些首先考虑如何添加动作的人,有两个选项,静态和动态。您只能设置4个选项,它会首先显示所有静态的,如果有空间,则显示动态的。
Here's how to add Static shortcuts. It's pretty easy, just add some keys on the main Info.plist
这是添加静态快捷方式的方法。很简单,只需在主键上添加一些键即可Info.plist
In this example i will be adding two static options one with Default Search icon, and the other with custom icon from asset catalog.
在这个例子中,我将添加两个静态选项,一个带有默认搜索图标,另一个带有资产目录中的自定义图标。
<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemTitle</key>
<string>Add Event (with custom icon)</string>
<key>UIApplicationShortcutItemType</key>
<string>com.reverse.appname.addevent</string>
<key>UIApplicationShortcutItemIconFile</key>
<string>custom-icon-from-asset-catalog</string>
<key>UIApplicationShortcutItemSubtitle</key>
<string>Here you can add some text below the option</string>
</dict>
<dict>
<key>UIApplicationShortcutItemTitle</key>
<string>Search Event (with default icon)</string>
<key>UIApplicationShortcutItemType</key>
<string>com.reverse.appname.searchevents</string>
<key>UIApplicationShortcutItemIconType</key>
<string>UIApplicationShortcutIconTypeSearch</string>
<key>UIApplicationShortcutItemSubtitle</key>
<string>Here you can add some text below the option</string>
</dict>
</array>
回答by iPrabu
With Xcode 7.3 you can test the 3D touch feature in simulator but with only one constraint. (Xcode7.3 release notes reference)
使用 Xcode 7.3,您可以在模拟器中测试 3D 触摸功能,但只有一个约束。(Xcode7.3 发行说明参考)
The machine(macbook/mac with trackpad) your are developing should have 3D touch capability.
您正在开发的机器(macbook/mac with trackpad)应该具有 3D 触摸功能。
You can find it under iOS simulator Hardware menu.
您可以在 iOS 模拟器硬件菜单下找到它。
Comments from Pavel Alexeev: Be sure to enable “Force Click and haptic feedback” in System Preferences → Trackpad
来自 Pavel Alexeev 的评论:请务必在系统偏好设置 → 触控板中启用“强制点击和触觉反馈”
回答by Jeremy Huddleston Sequoia
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.
iOS 中的强制压力(例如:Peek & Pop)不会通过 Xcode 7.0 或 Xcode 7.1 Beta 的模拟器公开。压力触摸选项仅与模拟器版本中的 watchOS 设备相关。如果您有 Xcode 7.1 beta,您会注意到菜单选项实际上已禁用。
With Xcode 7.3 and the iOS 9.3 and later simulator runtimes, you can test peek/pop functionality using a force touch trackpad.
使用 Xcode 7.3 和 iOS 9.3 及更高版本的模拟器运行时,您可以使用强制触摸触控板测试 peek/pop 功能。
回答by sanky009
You can enable 3D Touch in simulator. Thanks to thislibrary.
您可以在模拟器中启用 3D Touch。感谢这个图书馆。
After adding it Using a combination of the command, control, and shiftkeys 3D Touch can be enabled.
Don't forget to add library in Debugenvironment only. Exclude it from Releaseenvironment.
添加后 使用命令、控制和移位键的组合可以启用 3D Touch。
不要忘记仅在调试环境中添加库。从发布环境中排除它。
回答by Jordan Smith
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).
这里有一些代码可以让您在模拟器中测试 3D Touch peek & pop。请记住,这是 iOS 9.0 的代码,一些内部/私有方法在 9.1 中发生了变化,因此您需要进行一些小的更改(提示:“位置”一词在其中一个更改为“位置”方法名)。
https://gist.github.com/nickfrey/07e2c6d8d2e5444fb91d
https://gist.github.com/nickfrey/07e2c6d8d2e5444fb91d
Both this and https://github.com/DeskConnect/SBShortcutMenuSimulatormentioned in other answers allow you to test for 3D Touch without an actual device fairly competently.
这和其他答案中提到的https://github.com/DeskConnect/SBShortcutMenuSimulator都允许您在没有实际设备的情况下相当称职地测试 3D Touch。
回答by Andrew
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
创建了一个 UIMutableApplicationShortcutItem 对象
将其放入 launchOptions 以
UIApplicationLaunchOptionsShortcutItemKey
就是这样
It looks like user did the 3d touch on the app icon.
看起来用户对应用程序图标进行了 3d 触摸。
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:)
(应用程序:didFinishLaunchingWithOptions:)
回答by Jayprakash Dubey
Officially Xcode 7.1 supports 3D touch but not on simulator. You need to have actual device in order to test. Check last paragraph of documentationfrom Apple.
Xcode 7.1 正式支持 3D 触控,但不支持模拟器。您需要有实际设备才能进行测试。检查Apple文档的最后一段。
However, you can use third-party tools to test it on simulator such as one highlighted by Nicolas Sabove.
但是,您可以使用第三方工具在模拟器上对其进行测试,例如上面Nicolas S突出显示的模拟器。
回答by atulkhatri
The newer macbooks are having force-touch enabled touch pad. I think these options will only work in that.
较新的 macbook 具有强制触摸功能的触摸板。我认为这些选项只会在这种情况下起作用。
回答by karthik
It worked for me with XCode 9 & iphone 8 simulator. In your mac go to system preference -> Trackpad -> Enable Force click and haptic feedback.
它适用于 XCode 9 和 iphone 8 模拟器。在您的 Mac 中,转到系统首选项 -> 触控板 -> 启用强制点击和触觉反馈。
Then press firmly on any part of iphone simulator to perform force touch action.
然后用力按压 iphone 模拟器的任何部分以执行强制触摸动作。