I want to place an MPVolumeView
in my SwiftUI view but it doesn't behave like a normal SwiftUI view. I want the volume slider to be centered vertically between the two dividers. If you replaced VolumeSlider
with Text
it would be centered. How can I make the VolumeSlider
behave in the same way?
// Must be run on real device, not simulator
import SwiftUI
import MediaPlayer
struct ContentView: View {
var body: some View {
VStack {
Divider()
VolumeSlider()
.frame(height: 128)
Divider()
}
}
}
struct VolumeSlider: UIViewRepresentable {
func makeUIView(context: Context) -> MPVolumeView {
MPVolumeView(frame: .zero)
}
func updateUIView(_ view: MPVolumeView, context: Context) {}
}