对TapGesture进行注释会激活声音。但是振动不起作用。如何将声音和振动结合起来?
为什么会出现这个问题?
let feedback = UIImpactFeedbackGenerator(style: .soft)
func activeNum() {
playSound(sound: "casino-chips", type: "mp3")
}
var body: some View {
ZStack {
VStack(spacing: 0) {
LogoView()
Spacer()
Button(action: {
self.activeNum()
}) {
Image(systemName: "heart.fill")
.resizable()
.frame(width: 100, height: 100, alignment: .center)
.foregroundColor(.gray)
// .onTapGesture {
// feedback.impactOccurred()
// }
}
Spacer()
}
}
}
在Button
操作中,同时调用activeNum()
和impactOccured()
,而不是尝试将后者放在单独的onTapGesture
:中
Button(action: {
self.activeNum()
feedback.impactOccurred()
}