如何让iPhone使用Swift振动? [英] How to make iPhone vibrate using Swift?
本文介绍了如何让iPhone使用Swift振动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要让iPhone振动,但我不知道如何在Swift中做到这一点。我知道在Objective-C中你只需写:
I need to make the iPhone vibrate, but I don't know how to do that in Swift. I know that in Objective-C, you just write:
import AudioToolbox
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
但这对我不起作用。
推荐答案
简短示例:
import UIKit
import AudioToolbox
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
}
}
加载到手机上会震动。您可以根据需要将其放入函数或IBAction中。
load onto your phone and it will vibrate. You can put it in a function or IBAction as you wish.
这篇关于如何让iPhone使用Swift振动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文