Will
Will

Reputation: 25

Can I invert clipShape to cut out shape from another shape in SwiftUI?

I have a blue Rectangle overlaying a camera preview layer inside of a ZStack.

What I want to do is cut a RoundedRectangle "frame" out of the blue Rectangle so the camera preview layer has a blue framing with rounded corners.

How do I cut out a RoundedRectangle from the Blue Rectangle to reveal the preview layer below? Is there a way to invert the clip-shape??

Below is a picture of what I currently have, the black color represents the camera preview layer which is currently hidden by the blue Rectangle.

struct CameraView: View {

   var body: some View {
       ZStack {  // can I invert this clipshape to reveal camera view??
          Rectangle().ignoresSafeArea(.all).foregroundColor(.blue).clipShape(
               RoundedRectangle(cornerRadius: 20.00)
             )
          CameraPreviewLayer() // represented by BLACK color
          ShutterButton()
       }
   }
}



enter image description here

Upvotes: 1

Views: 442

Answers (1)

Moose
Moose

Reputation: 2737

Can't you use the .cornerRadius() attribute on the ztack or cameraPreviewLayer ?

Upvotes: 1

Related Questions