如何检测iphone中的摇晃方向 [英] how to detect direction of shake in iphone

查看:92
本文介绍了如何检测iphone中的摇晃方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个瓶子的图像,每当用户摇动设备时,我想在那个方向上移动该图像。
喜欢向上,向下,向左或向右。

I have an image of a bottle, whenever user shakes the device i want to move that image in that direction. like up, down, left or right.

例如:如果用户向左摇动设备我想向左移动该图像。

For example: if user is shaking the device in left direction i want to move that image in left direction.

我可以使用

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if(event.subtype==UIEventSubtypeMotionShake)
{/*some code*/} }

但我不知道如何检测方向。

but i dont know how to detect the direction.

即使这是可能的或不。
请帮帮我。

i dont even if this is possible or not. please help me.

推荐答案

震动通常是来回运动。使用加速度计数据检测一个特定方向(例如左侧)的突然移动或朝向不同方向的倾斜。

A shake is typically a back and forth movement. Use the accelerometer data to detect a sudden movement in one particular direction (e.g. left) or a tilt towards a different orientation.

这篇关于如何检测iphone中的摇晃方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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