Home > AI > IOS > SwiftUI >

GeometryProxy

The geo in GeometryReader is GeometryProxy.


import SwiftUI


struct ContentView: View {
    @EnvironmentObject var home: HomeGlobal
    
    var body: some View {
        
        ZStack{
            Circle()
                .frame(width: home.defaultPadding*4, height: home.defaultPadding*4)
                .foregroundColor(Color.blue.opacity(0.2))
            

            
            Circle()
                .stroke(lineWidth: 1)
                .frame(width: home.defaultPadding*3.6, height: home.defaultPadding*3.6)
                .foregroundColor(.white)
            
            
            GeometryReader { geo in
                CircleLineView(geo: geo)
            }
            
            
            Circle()
                .frame(width: home.defaultPadding*2.6, height: home.defaultPadding*2.6)
                .foregroundColor(.white)
            VStack{
                Text("命中率")
                    .font(home.fontFootnote)
                    .bold()
                    .foregroundColor(.blue)
                Text("90%")
                    .font(home.fontFootnote)
                    .bold()
                    .foregroundColor(.blue)
            }
        } // ZStack
        .fixedSize()
    
    }
}



struct CircleLineView: View {

    @EnvironmentObject var home: HomeGlobal
    var geo: GeometryProxy
    
    init(geo: GeometryProxy) {
        self.geo = geo
        print(geo.size.width)
    }
    
    var body: some View {
        
        Path{ path in
            path.addArc(center: CGPoint(x: geo.size.width/2, y:geo.size.height/2),
                        radius: home.defaultPadding*1.55,
                        startAngle: .degrees(-90),
                        endAngle: .degrees(180),
                        clockwise: false)

        }
        .stroke(style: StrokeStyle(lineWidth: home.defaultPadding/2, lineCap: .round, lineJoin: .round))
        .foregroundColor(.blue)

    }
}




Relevant tags:

Leave a Reply