I’ve a view with a map and I’ve a .sheet
that reveals up when a marker is tapped. This sheet has some .presentationDentents
with .fraction
and if the fraction is simply too small and doest match the entire view, as an alternative of creating the highest of the view persist with the highest of the sheet it sticks the center of it, leaving the highest the place the consumer cannot see it.
That is my .sheet
a part of the code in MapView
.sheet(merchandise: $selectedCity) { metropolis in
DetailCityView(for: metropolis)
.presentationDetents([.fraction(0.15), .large])
}
And that is my DetailCityView
:
struct DetailCityView: View {
var metropolis: Metropolis
@Setting(.dismiss) var dismiss
@Setting(.modelContext) var modelContext
init(for metropolis: Metropolis) {
self.metropolis = metropolis
}
var physique: some View {
VStack {
HStack {
VStack(alignment: .main) {
Textual content(metropolis.identify)
.font(.title2)
.fontWeight(.daring)
Textual content(metropolis.nation)
.font(.subheadline)
.foregroundStyle(.grey)
.lineLimit(2)
.padding(.trailing)
}
Spacer()
Button{
dismiss()
} label: {
Picture(systemName: "xmark.circle.fill")
.resizable()
.body(width: 24, peak: 24)
.foregroundStyle(.grey, Shade(.systemGray5))
}
}.padding(.backside)
let uiImage = UIImage(information: metropolis.mainImage.imageData)!
Picture(uiImage: uiImage)
.resizable()
.aspectRatio(contentMode: .fill)
.body(peak: 150)
.clipShape(RoundedRectangle(cornerRadius: 15))
Button {
deleteCity(metropolis: metropolis)
dismiss()
} label: {
Label("Delete Metropolis", systemImage: "trash")
.daring()
.foregroundStyle(.white)
.body(maxWidth: .infinity, alignment: .heart)
.body(peak: 50)
.background(.purple)
.clipShape(RoundedRectangle(cornerRadius: 10))
}
.buttonStyle(.customized)
.padding(.high)
}
.body(maxWidth: .infinity, maxHeight: .infinity, alignment: .high)
.padding()
}
func deleteCity(metropolis: Metropolis) {
withAnimation {
metropolis.journey?.cities.removeAll { $0.id == metropolis.id }
do { attempt modelContext.save() }
catch { print("Failed to avoid wasting modifications: (error)") }
}
}
}
I’ve tried inserting Spacers
and making the body sizes completely different I did not get any outcomes.
Utilizing ViewThatFits
additionally did not work.
I noticed this response on one other customers query that had the identical concern, and im undecided if there’s a easier technique to do it.
Here’s what it appears to be like like proper now:
With an even bigger presentationDetent
:
What I would like it to seem like:
Proper now its not an enormous downside as a result of I could make the presentationDetents
greater however I additionally need to put some textual content and possibly one thing extra that can use extra of that peak and I just like the look of it being sort of small.