Claus Strandberg
Claus Strandberg

Reputation: 139

Use SwiftUI to create a sheet menu that adapts to a wide screen like the Apple Maps App

How to use SwiftUI to create a sheet menu that adapts to a wide screen like the Apple Maps App

Apple Map App side sheet menu in horizontal screen

I tried to use Sheet directly and changed the height and allowed to interact with the background by getting sheetPresentationController, but in the iPad or horizontal iPhone, I can't find a suitable way to align the menu to one side and allow it to interact with the background.

I also tried to use other third-party configurations, but there are not many adaptations, and the appearance is not similar to sheet. How do I need to make such a sheet menu just like in Apple Map app?

I tried to set the sourceView in sheetPresentationController, but it didn't work. Using Sheet directly on the iPad will display in the center of the screen, and problems will occur when adapting to the horizontal iPhone.

Upvotes: 13

Views: 1026

Answers (1)

Arun Panneerselvam
Arun Panneerselvam

Reputation: 2335

you can specify view options inside the sheet like this,

.sheet(isPresented: $showOptions) {
                EmptyView()
                .presentationDetents([.fraction(0.1), .medium, .large])
                .presentationDragIndicator(.visible)
                .presentationBackgroundInteraction(.enabled)
                .interactiveDismissDisabled()
            }

Upvotes: 0

Related Questions