我希望在视图旋转时播放有节奏的声音,具体取决于速度。这里我有UIview的旋转动画。
var spinAnimation : CABasicAnimation = CABasicAnimation(keyPath: "transform.rotation")
spinAnimation.fromValue = 0
spinAnimation.toValue = NSNumber(double: 10.0+Double(arc4random_uniform(360))*M_PI * 3)
spinAnimation.duration = 5
spinAnimation.delegate = self
spinAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
layer.addAnimation(spinAnimation, forKey: "SpinAnimation")
如何通过声音向用户反馈旋转速度?
答案 0 :(得分:0)
在苹果开发者文档中,他们提供了更改音乐音量的选项,pl。请参阅以下网址
您可以使用以下代码段作为参考
var spinnigSpeedMusic= AVAudioPlayer()
var spinningMusicUrl:NSURL = NSBundle.mainBundle().URLForResource("spinningSpeed", withExtension: ".mp33")
spinnigSpeedMusic = AVAudioPlayer(contentsOfURL:spinningMusicUrl, error: nil)
spinnigSpeedMusic.prepareToPlay()
spinnigSpeedMusic.play()
spinnigSpeedMusic.volume = 0.1 // this value can be changed from 0.0 to 1, based on the rotation speed.