iOS运动检测:运动检测灵敏度级别 [英] iOS Motion Detection: Motion Detection Sensitivity Levels

查看:150
本文介绍了iOS运动检测:运动检测灵敏度级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题。我正在尝试检测用户何时摇动iPhone。我有适当的标准代码来检测运动,这没问题。但是,在我的实际手机上进行测试时,我意识到您必须非常摇晃设备才能触发运动检测。我想知道是否可以实施某种程度的敏感性检查。例如,一种检测用户是否轻度摇晃设备或轻度晃动与剧烈晃动之间的方式的方法。这将针对iOS 7,因此任何未从旧iOS版本弃用的提示或建议将不胜感激。我已经完成了谷歌搜索,但尚未找到解决该问题的任何好的方法(如果有的话)。

I have a simple question. I'm trying to detect when a user shakes the iPhone. I have the standard code in place to detect the motion and this works no problem. However, in testing this on my actual phone, I've realized that you have to shake the device quite hard to get the motion detection to trigger. I would like to know if there is a way to implement a level of sensitivity checking. For example, a way to detect if a user lightly shakes the device or somewhere between light and hard shake. This will be targeted towards iOS 7 so any tips or advice that is not deprecated from older iOS version would be greatly appreciated. I've done my googling but have yet to find any good solutions to this problem (If there are any.)

谢谢!

-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    if(motion == UIEventSubtypeMotionShake)
    {
       //Detected motion, do something about it 
       //at this point.
    }
}

-(BOOL)canBecomeFirstResponder
{
    return YES;
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self becomeFirstResponder];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [self resignFirstResponder];
    [super viewWillDisappear:animated];
}


推荐答案

使用核心运动。
将您的二进制文件与CoreMotion框架链接。
在您的班级中包含#import。
创建CMMotionManager的实例。
将deviceMotionUpdateInterval属性设置为适当的值。
然后调用startDeviceMotionUpdatesToQueue。
您将在块内获得连续更新,其中包括加速度,磁场,旋转等。
您将获得所需的数据。
要注意的一件事是,如果间隔太小,更新将是如此之快,因此您将必须采用适当的逻辑来处理该更新。

Use core motion. Link your binary with CoreMotion framework. Include #import in your class. Create an instance of CMMotionManager. Set the deviceMotionUpdateInterval property to a suitable value. Then call startDeviceMotionUpdatesToQueue. You will get continuous updates inside the block, which includes acceleration, magnetic field, rotation, etc. You will get the data you require. One thing to be taken care of is that the update shall be so rapid if the interval is too small, and hence you will have to employ suitable logic to handle the same.

这篇关于iOS运动检测:运动检测灵敏度级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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