I am using a .fullScreenCover
to present a VideoPlayer
view. On iOS 15 and below, doing so shows the close button in the top-left, like below:
But on iOS 16, it doesn’t seem to appear.
Code is below:
.fullScreenCover(
isPresented: $showVideoSheet,
onDismiss: {
selectedVideo = nil
},
content: {
if let video = selectedVideo {
VideoPlayerView(video: video)
}
}
)
VideoPlayerView
is below:
struct VideoPlayerView: View {
@StateObject var model: VideoPlayerViewModel
let video: VideoModel
init(video: VideoModel) {
self._model = StateObject(wrappedValue: VideoPlayerViewModel(video: video))
self.video = video
}
var body: some View {
if let player = model.player {
VideoPlayer(player: player)
.ignoresSafeArea()
}
}
}
The view model just loads the AVPlayer etc.
Any suggestions?
3
Answers
You can make your own close button.
I’m facing the exact same situation and I solved it similarly to what Tamás suggested. I added a close button only for versions starting at iOS 16, given that former versions already present the button.
Also, I tried to design the button similarly to the sound button already existing on the top rightmost side of the screen which now doesn’t contain a surface around it.
You can create player using UIViewControllerRepresentable instead VideoPlayer.