我正在为 tvOS 开发一款 SwiftUI 应用。我有一个带有图片和一行文本的 NavigationLink。该项目按预期工作,当聚焦时它会变大。但是,如果我更改圆角半径(默认值太大),那么即使圆角半径变小并且图片和文本变大,图片也会被剪裁(图片会变大但其边界保持不变)。我该如何解决这个问题?
NavigationStack {
ScrollView {
VStack(alignment: .leading, spacing: 20) {
ForEach(sections) { section in
VStack(alignment: .leading, spacing: 20) {
// Section title
Text(section.title)
.font(.title)
.padding(.horizontal)
// Items
ScrollView(.horizontal) {
LazyHStack(spacing: 50) {
ForEach(section.items) { item in
NavigationLink {
VideoDetailView(mediaItem: item)
} label: {
AsyncImage(url: item.imageURL) { phase in
switch phase {
case .empty:
// This shows while the image is loading
ProgressView()
.aspectRatio(700/500, contentMode: .fit)
.containerRelativeFrame(.horizontal, count: 6, spacing: 50)
case .success(let image):
// This shows the successfully loaded image
image
.resizable()
.aspectRatio(700/500, contentMode: .fit)
.containerRelativeFrame(.horizontal, count: 6, spacing: 50)
case .failure(_):
// This shows if the image fails to load
Image(systemName: "photo")
.resizable()
.aspectRatio(700/500, contentMode: .fit)
.containerRelativeFrame(.horizontal, count: 6, spacing: 50)
@unknown default:
// Any other
EmptyView()
}
} .cornerRadius(5) // WHen I add this, the image gets clipped
Text(item.title)
//Text(item.subtitle)
}
.buttonStyle(.borderless)
}
}
}
.scrollClipDisabled()
}
}
}
}
}