ios – How do I make content material persist with high on SwiftUI sheet as an alternative of the center

ios – How do I make content material persist with high on SwiftUI sheet as an alternative of the center


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:

enter image description here

With an even bigger presentationDetent:

enter image description here

What I would like it to seem like:

enter image description here

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.

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog. 
rooshohttps://www.roosho.com
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog. 

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here


Latest Articles

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog.