visit
So, I have some code like this:
GeometryReader {
geometry in
self.badgeSymbols
.scaleEffect(1.0 / 4.0, anchor: .top)
.position(x: geometry.size.width / 2.0,
y: (3.0 / 4.0) * geometry.size.height)
}
GeometryReader {
geometry in
var width = geometry.size.width ;
var height = geometry.size.height;
self.badgeSymbols
.scaleEffect(1.0 / 4.0, anchor: .top)
.position(x: width / 2.0,
y: (3.0 / 4.0) * height)
}
It should work just fine according to my knowledge.
How ever I get an error like this:Encounter a strange error, I went to google the answer.
And following is my found:1. Curly braces`{ ...body...}` after the GeometryReader is a syntax called closure. In this case, we call GeometryReader to initialize a GeometryReader instance. According to the Documentation of GeometryReader by Apple. GeometryReader {
geometry in
var width = geometry.size.width ;
var height = geometry.size.height;
self.badgeSymbols
.scaleEffect(1.0 / 4.0, anchor: .top)
.position(x: geometry.size.width / 2.0, y: (3.0 / 4.0) * geometry.size.height)
return Text("Position:x: \(geometry.size.width / 2.0) y: \((3.0 / 4.0) * geometry.size.height))")
}
GeometryReader<Text> {
geometry in
var width = geometry.size.width ;
var height = geometry.size.height;
self.badgeSymbols
.scaleEffect(1.0 / 4.0, anchor: .top)
.position(x: geometry.size.width / 2.0, y: (3.0 / 4.0) * geometry.size.height)
return Text("Position:x: \(geometry.size.width / 2.0) y: \((3.0 / 4.0) * geometry.size.height))")
}
@frozen struct GeometryReader<Content> where Content : View