I'm working on a SwiftUI app where I have a ZStack that has a ViewController (wrapped in a UIViewRepresentable view) underneath and a semitransparent SwiftUI view on top. I need to be able to tap through the SwiftUI view to the ViewController, but this does not seem to work.
I've tried setting the SwiftUI view with .disabled(true) and .allowsHitTesting(false), but neither seem to resolve the issue. I've also tried using an overlay instead of a ZStack, but this did not help either.
How do I put a SwiftUI View above a ViewController and allow taps/scrolls/other gestures to pass through to the ViewController?
I made a sample project with 2 identical versions - it worked fine in the version with a SwiftUI view underneath, but did not work in the version with the ViewController underneath.
SwiftUI only version (tapping on the red view passes through correctly):
struct SwiftUIOnlyView: View {
var body: some View {
ZStack {
Color.white.onTapGesture {
print("tapped \(Date())")
}
Color.red
.disabled(true)
.opacity(0.20)
.frame(width: 100, height: 100, alignment: .center)
}
}
}
SwiftUI red view above a ViewController with a full screen button (tapping outside the red view works fine, but tapping on the red view does not pass through to the ViewController):
struct SwiftUIAndViewControllerView: View {
var body: some View {
ZStack {
ViewControllerWrapperView()
Color.red
.disabled(true)
.opacity(0.20)
.frame(width: 100, height: 100, alignment: .center)
}
}
}
struct ViewControllerWrapperView: UIViewControllerRepresentable {
func makeUIViewController(context: UIViewControllerRepresentableContext<ViewControllerWrapperView>) -> ViewController {
return ViewController()
}
func updateUIViewController(_ uiViewController: ViewController, context: UIViewControllerRepresentableContext<ViewControllerWrapperView>) {
}
}
class ViewController: UIViewController {
@IBAction func didTap(_ sender: Any) {
print("tapped \(Date())")
}
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi, I'm working on an app where a user can scroll through a feed of short videos (a bit like TikTok). I do some pre-fetching of videos a couple positions ahead of the user's scroll position, so the video can start playing as soon as he or she scrolls to the video.
Currently, I just pre-fetch by initializing a few AVPlayers. However, I'd like to add a better caching system.
I'm looking for the best way to: get videos to start playing as possible, while
making sure to minimize re-downloading of videos if a user scrolls away from a video and back to it.
Is there a way that I can cache the contents of an AVPlayer that has loaded an HLS video?
Alternatively, I've explored using AVAssetDownloadTask to download the HLS videos. My issue is that I can't download the full video and then play it - I need to start playing the video as soon as the user scrolls to it, even if it's not done downloading.
Is there a way to start an HLS download with an AVAssetDownloadTask, and then start playing the video while it continues downloading?
Thank you!