如何在 iPhone 上区分摇晃和倾斜 [英] How can I differentiate a Shake vs a Tilt on the iPhone
问题描述
我有一个页面 UIScrollView,它会根据手机的倾斜向左或向右滚动 1 页.
I have a page UIScrollView that will scroll 1 page left or right depending on the tilt of the phone.
我也想实现随机页面抖动",但无法弄清楚如何区分抖动运动和 x 轴倾斜的逻辑.
I would also like to implement "Shake for a random page", but cannot figure out how to do the logic for differentiating a shake motion and a x-axis tilt.
这两个动作可以一起使用吗?我不需要任何复杂的事情,比如倾斜时摇晃,我只希望两者独立工作.
Can these two motions be used in conjunction with one another? I don't need anything complicated like shaking while tilting, I just want both to work independently of one another.
推荐答案
要检测抖动",您需要检查生成的 g-force.摇晃和倾斜会更高.
To detect a "shake" you would check the g-force generated. It will be higher for a shake vs a tilt.
您绝对可以同时使用两者,只需检查 g-force 的值是否足够高以指示抖动(> 1g - 调整以获得您喜欢的灵敏度),然后如果没有检测到抖动,则跌落到倾斜检查.
You can definitely use both at the same time, just check the g-force for a high enough value to indicate a shake (> 1g - adjust to get the sensitivity to your liking), then if no shake is detected fall through to the tilt checking.
这篇关于如何在 iPhone 上区分摇晃和倾斜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!