Ios Xcode编译器错误:编译器无法在合理时间内对此表达式进行类型检查(Xcode 12.0 SwiftUI)
(Xcode 12.0,SwiftUI) 这段代码为我工作了将近6个月,没有任何问题。我昨天刚收到这个错误,没有进行任何编辑。我尝试了很多清理代码并缩短它,但没有任何效果Ios Xcode编译器错误:编译器无法在合理时间内对此表达式进行类型检查(Xcode 12.0 SwiftUI),ios,swift,swiftui,Ios,Swift,Swiftui,(Xcode 12.0,SwiftUI) 这段代码为我工作了将近6个月,没有任何问题。我昨天刚收到这个错误,没有进行任何编辑。我尝试了很多清理代码并缩短它,但没有任何效果 GeometryReader { (geometry: GeometryProxy) in ForEach(0..<5) { index in Group { Circle() .foregroundColor(Color("GreyOne"))
GeometryReader { (geometry: GeometryProxy) in
ForEach(0..<5) { index in
Group {
Circle()
.foregroundColor(Color("GreyOne"))
.frame(width: geometry.size.width / 5, height: geometry.size.height / 5)
.scaleEffect(!self.isAnimating ? 1 - CGFloat(index) / 5 : 0.2 + CGFloat(index) / 5)
.offset(y: geometry.size.width / 10 - geometry.size.height / 2)
}.frame(width: geometry.size.width, height: geometry.size.height)
.rotationEffect(!self.isAnimating ? .degrees(0) : .degrees(360))
.animation(Animation
.timingCurve(0.5, 0.15 + Double(index) / 5, 0.25, 1, duration: 1.5)
.repeatForever(autoreverses: false))
}
}.aspectRatio(1, contentMode: .fit)
.onAppear {
self.isAnimating = true
}
GeometryReader{(几何体:GeometryProxy)位于
弗雷奇(0..您可以将视图的部分
移到单独的私有函数中,只需从主体
调用这些函数即可。您的代码中有几个编译器错误,例如没有将x
传递到偏移量
函数,或者没有将所有Int
s转换为CGFloat
。一旦您中断bod在您的视图中,真正的错误将浮出水面
下面是代码的编译版本,使用2个私有函数构建视图的主体部分
struct YourView: View {
@State private var isAnimating = false
var body: some View {
GeometryReader { geometry in
ForEach(0..<5) { index in
Group {
circle(geometry: geometry, index: index)
}
.frame(width: geometry.size.width, height: geometry.size.height)
.rotationEffect(!self.isAnimating ? .degrees(0) : .degrees(360))
.animation(animation(index: index))
}
}
.aspectRatio(1, contentMode: .fit)
.onAppear {
self.isAnimating = true
}
}
private func animation(index: Int) -> Animation {
Animation
.timingCurve(0.5, 0.15 + Double(index) / 5, 0.25, 1, duration: 1.5)
.repeatForever(autoreverses: false)
}
private func circle(geometry: GeometryProxy, index: Int) -> some View {
let width = geometry.size.width
let height = geometry.size.height
let yOffset = width / 10 - height / 2
let nonAnimatingScale = 1 - CGFloat(index) / CGFloat(5)
let animatingScale = 0.2 + CGFloat(index) / CGFloat(5)
return Circle()
.foregroundColor(Color("GreyOne"))
.frame(width: width / 5, height: height / 5)
.scaleEffect(self.isAnimating ? animatingScale : nonAnimatingScale)
.offset(x: 0, y: yOffset)
}
}
struct YourView:View{
@状态私有变量isAnimating=false
var body:一些观点{
GeometryReader{中的几何体
ForEach(0..Animation{
动画
.计时曲线(0.5,0.15+双指数)/5,0.25,1,持续时间:1.5)
.repeatForever(自动反转:false)
}
私有函数圆(几何体:GeometryProxy,索引:Int)->某些视图{
让宽度=几何体.size.width
让高度=几何体.size.height
让yOffset=宽度/10-高度/2
设非animatingscale=1-CGFloat(索引)/CGFloat(5)
设animatingScale=0.2+CGFloat(索引)/CGFloat(5)
返回圆()
.foregroundColor(颜色(“灰色”))
.框架(宽度:宽度/5,高度:高度/5)
.scaleEffect(自动画?动画缩放:非动画缩放)
.偏移量(x:0,y:y偏移量)
}
}
非常感谢您的帮助