0

注释 onTapGesture 会激活声音。但是振动不起作用。如何同时实现声音和振动?

为什么会出现这个问题?

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()
        }
    }
}
4

1 回答 1

0

在您的Button操作中,调用两者activeNum()impactOccured()而不是尝试将后者放在单独的onTapGesture

Button(action: {
 self.activeNum()
 feedback.impactOccurred()
}
于 2021-06-28T05:46:12.410 回答