3D触控/强制触控实现 [英] 3D touch/Force touch implementation

查看:209
本文介绍了3D触控/强制触控实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何实施3D触摸以检查用户是否点击 UIView 或强制触摸 UIView

How can we implement 3D touch to check if the user taps on UIView or force touch on UIView?

有没有办法用 UIGestureRecognize 或仅用 UITouch

推荐答案

您可以在没有指定手势识别器的情况下执行此操作。您不需要调整touchesEnded和touchesBegan方法,而只需要touchesMoved来获取正确的值。从开始/结束获得uitouch的力量将返回奇怪的值。

You can do it without a designated gesture recognizer. You do not need to adjust the touchesEnded and touchesBegan method, but simply the touchesMoved to obtain the correct values. getting the force of a uitouch from began/ended will return weird values.

UITouch *touch = [touches anyObject];

CGFloat maximumPossibleForce = touch.maximumPossibleForce;
CGFloat force = touch.force;
CGFloat normalizedForce = force/maximumPossibleForce;

然后,设置一个强制阈值并将normalizedForce与此阈值进行比较(0.75对我来说似乎没问题)。

then, set a force threshold and compare the normalizedForce to this threshold (0.75 seems fine for me).

这篇关于3D触控/强制触控实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆