gpt4 book ai didi

ios - iOS中如何实现长振动

转载 作者:行者123 更新时间:2023-11-29 05:41:41 25 4
gpt4 key购买 nike

我想制作一个按钮,按下后手机就会振动。当您松开时,振动应该停止。理想情况下,它具有触摸灵敏度,因此按得越用力,嗡嗡声就越强。

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)

目前,这仅播放 1 个嗡嗡声,循环仍然有轻微的断开连接,但循环仍然是一种不需要的解决方法。

最佳答案

显然,您可以通过以下方式使手机振动:

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 可以提高触觉反馈/系统振动的速度。

关于ios - iOS中如何实现长振动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56485835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com