我想要一个功能,我想检测我的设备是否正在震动。问题是我可以使用 UIAcceleratorDelegate 的 didAccelerate 方法检测震动,但我不知道如何检测设备是否仍在震动。我想在用户第一次摇动设备时播放音频文件,我必须检查用户在播放第一个音频文件时是否仍在摇动设备,如果仍在摇动,那么我必须播放另一个文件。
I want a functionality in which i want to detect if my device is being shaked.The problem is i can detect the shake with didAccelerate method of UIAcceleratorDelegate , but i dont know how to detect if the device is still shaking. I want to play an audio file when the user shakes the device for first time,i have to check if the user is still shaking the device while playing the 1st audio file,if it is still being shaked, then i have to play another file.
发布评论
评论(2)
您可能会考虑编写一个在单独的线程中运行的方法,该方法会轮询您的设备是否时不时地摇晃,并触发您在代码中其他位置处理的事件(或者代替它,处理您想要在线程中处理的任何内容)上下文本身,即使很困难我也不建议这样做)。
您只需确保您的“shake-detektor”线程在某个时间点退出,您可能希望在第二个音频文件停止播放时执行此操作。所以你的循环可以在该条件下进行测试。
希望我能帮一点忙。
You might consider writing a Method that runs in a separate thread that polls wether your device is being shaken every now and then and fire events that you handle somewhere else in your code (or instead of that, handle whatever you want to handle within the threads context itself, even tough i would not recommend doing that).
You just have to make sure, that your "shake-detektor"-thread exits at some point in time, you probably want to do that when the second audio file stopped playing. So your loop could test on that condition.
Hope I could help a bit.
请参阅示例项目 GLPaint 来自 Apple,通过访问 http://developer.apple.com/ 找到iPhone 并在搜索框中输入“shake”。不需要开发者帐户。
See the sample project GLPaint from Apple which was found by visiting http://developer.apple.com/iphone and entering "shake" in the search box. Developer account not required.