如何播放音频文件只有在用户晃动iPhone? [英] How to play an audio file ONLY while user is shaking iPhone?

查看:128
本文介绍了如何播放音频文件只有在用户晃动iPhone?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了许多关于如何检测震动的职位,但我不知道:

I've read a number of posts regarding how to detect shakes but I'm not sure:


  1. 目前什么是检测抖动的最佳方式?

  1. What is currently the best way to detect shakes?


  • 和 -

如何播放音频文件的只有的当用户晃动iPhone?

How to play an audio file ONLY while the user is shaking the iPhone?

任何人都有一个建议,例子/教程或样品code?

Anyone have an advice, examples/tutorials or sample code?

感谢

推荐答案

使用的<一个href=\"http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIAccelerometer_Class/Reference/UIAccelerometer.html\"相对=nofollow> UIAccelerometer 贯彻<一个href=\"http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIAccelerometerDelegate_Protocol/UIAccelerometerDelegate/UIAccelerometerDelegate.html\"相对=nofollow> UIAccelerometerDelegate 在你的类协议。也许你可以做这样的事情:

Use the UIAccelerometer and implement the UIAccelerometerDelegate protocol in your class. Perhaps you could do something like this:

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acc {
  float twoGs = 2.0;
  if ((acc.x * acc.x) + (acc.y * acc.y) + (acc.z * acc.z) > twoGs * twoGs) {
    if ([self paused]) {
      [self play];
    }
  } else {
    if ([self playing]) {
      [self pause];
    }
  }
}

有关暂停合适的实现,暂停,播放,播放选择。

for suitable implementations of the pause, paused, play, playing selectors.

这篇关于如何播放音频文件只有在用户晃动iPhone?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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