如何在iOS中长时间振动

时间:2019-06-06 22:30:08

标签: ios swift vibration audiotoolbox

我想按一个按钮,然后手机振动。释放时,振动应停止。理想情况下,它将具有触摸灵敏度,因此按得越厉害,嗡嗡声就越强。

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)

当前,它只发出1次嗡嗡声,并且循环仍然具有轻微的断开连接,但是循环仍然是不需要的解决方法。

1 个答案:

答案 0 :(得分:0)

显然,您可以使用以下方法使手机振动:

import UIKit
import AudioToolbox

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))            
    }

}

(此示例来自帖子here

如果希望振动是不确定的且连续的,则可以使用计时器顺序播放。但是显然,this is a common cause of app rejection from the App store,所以我不推荐它。

我不确定是否有用于提高触觉反馈/系统振动速度的API。