I would like to implement this "swipe up view" from the apple "find my" app in my app with swiftui. Does anyone know how this works or what I can look for? Best regards
Yeah, presenting a sheet isn’t quite the same, and there’s no built-in SwiftUI view that will do this.
Here are a few pointers in the right direction:
1
Try a ZStack as the basic structure:
ZStack(alignment: .bottom) {
mapView
sheetView
}
The sheet floats over the map and is aligned to the bottom (you can use .frame(height:) to set its height as needed). The mapView should be full height since the sheet background is translucent
2
A sheet background could look something like this:
And you could use a drag gesture to start working on implement detents:
@State var sheetHeight = 300.0
// in body:
sheetView
.frame(height: sheetHeight)
.gesture(DragGesture(minimumDistance: 1)
.onChanged{ v in
sheetHeight = 300 - v.translation.height
}
.onEnded{ _ in
sheetHeight = 300
}
)
From there, Maps has a ton of behavior: custom detents, content transitioning to scrollable at the top detent, icons showing and hiding, switch detent when the map is panned, etc.
There’s no magic built in way to do that stuff — it’s just custom UI work. No reason you can’t implement it in SwiftUI (or in UIKit if you prefer). Have fun!
2
Answers
Starting with iOS 16, you can achieve these with the
presentationDetents(_:)
modifier.See this article for examples.
Yeah, presenting a sheet isn’t quite the same, and there’s no built-in SwiftUI view that will do this.
Here are a few pointers in the right direction:
1
Try a ZStack as the basic structure:
The sheet floats over the map and is aligned to the bottom (you can use
.frame(height:)
to set its height as needed). The mapView should be full height since the sheet background is translucent2
A sheet background could look something like this:
3
And you could use a drag gesture to start working on implement detents:
From there, Maps has a ton of behavior: custom detents, content transitioning to scrollable at the top detent, icons showing and hiding, switch detent when the map is panned, etc.
There’s no magic built in way to do that stuff — it’s just custom UI work. No reason you can’t implement it in SwiftUI (or in UIKit if you prefer). Have fun!