【发布时间】:2022-01-27 08:00:59
【问题描述】:
我正在我的 SwiftUI 应用程序中制作加载屏幕,直到内容显示为止,屏幕将在渐变内为白色和灰色设置动画。
当我尝试运行此代码时出现错误,Instance method 'fill(_:style:)' requires that 'some View'符合 'ShapeStyle' 出现在我的 RoundedRectangle 旁边我不知道为什么?
有什么想法吗?谢谢
struct LoadingMediaLibrary: View {
@State private var animateGradient = false
let size = UIScreen.main.bounds.width / 3.057
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(0..<4, id: \.self) { _ in
RoundedRectangle(cornerRadius: 20.00)
.fill(
LinearGradient(gradient: Gradient(colors: [Color.white, Color.gray]), startPoint: .top, endPoint: .bottom)
.onAppear {
withAnimation(.linear(duration: 2.0).repeatForever(autoreverses: true)) {
animateGradient.toggle()
}
}
)
.frame(width: size, height: size)
}
}
}.padding(.leading, 10).padding(.top, 10)
}
}
【问题讨论】: