Saturday, October 14, 2023
HomeiOS Developmentios - boundingRect in Path would not output something in SwiftUI

ios – boundingRect in Path would not output something in SwiftUI


I used to be making an attempt to create a perform for Path that divides the body in half.

extension Path {
    mutating func divideInHalf() {
        transfer(to: CGPoint(x: 0, y: boundingRect.midY))
        addLine(to: CGPoint(x: boundingRect.maxX, y: boundingRect.midY))
    }
}

Nonetheless, this appeared to do nothing. The truth is, I attempted experimenting with boundingRect however it refused to output something in any respect.

struct ContentView: View {
    @State non-public var textual content = "ready for worth..."
    
    var physique: some View {
        VStack {
            Textual content(textual content)  // This stays as "ready for worth..."
            Path { path in
                path.divideInHalf()
                textual content = "(path.boundingRect.top)"  // This does nothing
            }
            .stroke()
        }
    }
}

I believed possibly it had one thing to do with utilizing the inout variable so I attempted doing this as properly:

struct ContentView: View {
    @State non-public var textual content = "ready for worth..."
    
    var physique: some View {
        VStack {
            Textual content(textual content)  // This stays as "ready for worth..."
            Path { path in
                path.divideInHalf()
                let rect = Path { path in 
                    path.transfer(to: .zero)
                    path.addLine(to: CGPoint(x: 100, y: 100))
                }.boundingRect  // Getting the worth from the occasion straight

                textual content = "(rect.top)"  // This nonetheless does nothing
            }
            .stroke()
        }
    }
}

I attempted including extra strains to the trail however that also did nothing. Does anybody understand how boundingRect works? Why is it not outputting something, what am I lacking?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments