震动反馈效果
UIImpactFeedbackGenerator类
有三种类型
case light
case medium
case heavy
如下调用
if#available(iOS10.0, *) {
// let impactLight = UIImpactFeedbackGenerator.init(style: UIImpactFeedbackStyle.heavy)
let impactLight = UIImpactFeedbackGenerator.init(style: UIImpactFeedbackStyle.light)
// let impactLight = UIImpactFeedbackGenerator.init(style: UIImpactFeedbackStyle.medium)
impactLight.impactOccurred()// 触发震动
}else{
// Fallback on earlier versions
}
})
UINotificationFeedbackGenerator类
case success // 成功
case warning // 警告
case error // 错误
如下调用方法
let impactLight = UINotificationFeedbackGenerator()
let impactLight = UIImpactFeedbackStyle.init(rawValue: UINotificationFeedbackType.error)