1

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

Will
  • 25
  • 5
  • Does this answer your question? [SwiftUI add inverted mask](https://stackoverflow.com/questions/59656117/swiftui-add-inverted-mask) – jnpdx May 19 '21 at 15:15

1 Answers1

1

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

Moose
  • 2,607
  • 24
  • 23