My app has a sort of "HUD" that sits at the top of the screen. It contains some general information about gameplay, and a couple of interactive elements: a scrolling list of text and a button.
It's imbedded into the main view like this:
struct WindowedInGameView: View {
@Environment(GameModel.self) private var gameModel
var body: some View {
ZStack(alignment: .top) {
VStack {
HUDTopView()
switch(gameModel.game?.location.player_location)
{
case .plaza:
PlazaView()
case .city_hall:
CityHallView()
///... Lots of additional views...
default:
Text("Player is in unknown location.")
}
// --> Position 2
}
if gameModel.showConversationView {
... an overlay for NPC conversations...
}
if (gameModel.showNotificationView)
{
.. a notification overlay...
}
}
}
}
If HUDTopView() is at the indicated place at the top of the VStack, none of its interactive elements work: you can't press buttons, you can't scroll the text. Everything looks present and interactive, it just doesn't seem to receive any input.
If I move HUDTopView() to the bottom of the VStack (where the comment indicates "Position 2") it works just fine, except it's not where I want it to be located. So far as I can tell, its position alone is disabling it somehow.
In either case, any interactive elements in the views from the switch are acting fine, regardless of their position relative to the HUD view.
This fails in the same way on iOS, iPadOS, and macOS. (The visionOS implementation doesn't use this main view, so I haven't tried it there).
What it isn't:
the overlays at the bottom. Commenting them out doesn't change behaviour.
the ZStack - I can replace it with an HStack, and it still fails.
Anything about the container of this view -- it fails in preview
Anything about the HUDTopView() -- a simple button placed there becomes noninteractive, too.
I'm at a complete loss for what could possibly be causing this.
Topic:
UI Frameworks
SubTopic:
SwiftUI