Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

601
Views
Altura de contenido dinámico en VStack SwiftUI

¿Por qué no puedo cambiar dinámicamente el contenido en VStack si no tengo muchos objetos en ScrollView? Lo que es sorprendente, si hay muchos objetos, entonces todo cambia maravillosamente, pero si hay pocos, entonces el desplazamiento solo funciona hacia abajo (debido a esto, puede haber fallas al intentar desplazarse hacia arriba)

Mi código:

 import Introspect struct SwiftUIView: View { @StateObject var myCoord = MyCoord() var body: some View { VStack { Color.red .frame(height: myCoord.height) ScrollView { ForEach(0..<20) { _ in Color.green .frame(height: 20) } .background(Color.red) } .introspectScrollView { scroll in scroll.delegate = myCoord } } } } class MyCoord: NSObject, UIScrollViewDelegate, ObservableObject { let maxSize: CGFloat = 76 let minSize: CGFloat = 56 @Published var height: CGFloat = 76 func scrollViewDidScroll(_ scrollView: UIScrollView) { let size = maxSize - scrollView.contentOffset.y height = min(maxSize, max(minSize, size)) } }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Vista de desplazamiento

Se resolvió colocar todas las vistas en ZStack y agregar algunas vistas falsas en la vista de desplazamiento. 1 vista es responsable del tamaño en el que el pergamino no se puede caer. La vista 2 es responsable del tamaño entre el tamaño máximo y mínimo del encabezado Aquí hay algunos ejemplos

 import Introspect struct ContentView: View { @StateObject private var myCoord = MyCoord() var body: some View { let sizeOfPlaceholder = myCoord.maxSize - myCoord.minSize ZStack(alignment: .top) { VStack(spacing: 0) { Color.black .frame(height: myCoord.minSize) ScrollView { Color.brown .frame(height:sizeOfPlaceholder) ForEach(0..<20) { number in Text("\(number)") .background(Color.red) .frame(height: 20) } } .padding(.vertical, 1) .introspectScrollView { scroll in scroll.delegate = myCoord } } Color.green .frame(height: myCoord.height) } } } class MyCoord: NSObject, UIScrollViewDelegate, ObservableObject { let maxSize: CGFloat = 76 let minSize: CGFloat = 56 @Published var height: CGFloat = 76 func scrollViewDidScroll(_ scrollView: UIScrollView) { print(scrollView.contentOffset.y) let size = maxSize - scrollView.contentOffset.y height = min(maxSize, max(minSize, size)) } }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!