我在ScrollView的VStack中有几个视图。
其中一个包含的视图是一个列表,并且正在被VStack中的其他视图压缩,以使其不再可见。
这是我的代码:
.ready
以下是正在压缩的视图的代码:
import SwiftUI
struct MovieDetailView: View {
@ObservedObject private var detailVM = MovieDetailViewModel()
// Core data
@Environment(\.managedObjectContext) var managedObjectContext
var movie: Movie
@State private var showingAlert = false
init(movie: Movie) {
self.movie = movie
detailVM.getMovieDetails(id: movie.id)
detailVM.getRecommendedMovies(movie: movie.id)
// Stop Scrollview bounce
UIScrollView.appearance().bounces = false
}
var body: some View {
// Movie poster
MovieHeroImage(movie: movie)
ScrollView {
VStack(alignment: .leading) {
Text(movie.overview)
.font(.body)
.fixedSize(horizontal: false, vertical: true)
MovieInfoRow(movie: movie) // <- This view is being compressed and not visible
if detailVM.fetchedMovie?.credits != nil {
CastView(cast: (detailVM.fetchedMovie?.credits!.cast)!)
.buttonStyle(PlainButtonStyle())
}
RecommendedMoviesView(movies: detailVM.recommendedMovies)
}
}.padding()
}
}
struct MovieDetailView_Previews: PreviewProvider {
static var previews: some View {
MovieDetailView(movie: Movie.example)
}
}