Center an off screen SwiftUI view

Viewed 1000

I am trying to create a screen with a horizontally centered circle that is bigger than the actual screen's width. Unfortunately, I do not know how to center it horizontally and pin it to the top. Is there an easy way to achieve such results with SwiftUI?

struct DemoView: View {
    private let circleBackgroundPercentage: CGFloat = 1.3
    
    var body: some View {
        ZStack {
            GeometryReader { geometry in
                VStack(alignment: .center) {
                    Circle()
                        .fill(Color.yellow)
                        .frame(width: geometry.size.width * circleBackgroundPercentage, height: geometry.size.height * circleBackgroundPercentage, alignment: .center)
                }
            }
            Text("Demo")
        }.edgesIgnoringSafeArea(.all)
    }
}

The expected result] The current result

2 Answers

Here is possible approach to solve such kind to task.

Prepared with Xcode 12.4/iOS 14.4

demo

var body: some View {
    ZStack {
        VStack {
            Color.yellow
                .clipShape(Circle())
            Color.clear
        }
        .scaleEffect(1.8)   // << tune factor as needed !!
        Text("Demo")
    }.edgesIgnoringSafeArea(.all)
}
Related