【问题标题】:Can I invert clipShape to cut out shape from another shape in SwiftUI?我可以在 SwiftUI 中反转 clipShape 以从另一个形状中剪出形状吗?
【发布时间】:2021-05-19 15:10:12
【问题描述】:

我有一个蓝色矩形覆盖 ZStack 内的相机预览层。

我想要做的是从蓝色矩形中剪下一个 RoundedRectangle“框架”,这样相机预览层就有一个带圆角的蓝色框架。

如何从蓝色矩形中剪下一个圆角矩形以显示下面的预览层?有没有办法反转剪辑形状??

下面是我目前拥有的图片,黑色代表当前被蓝色矩形隐藏的相机预览层。

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()
       }
   }
}



【问题讨论】:

标签: swiftui


【解决方案1】:

你不能在 ztack 或 cameraPreviewLayer 上使用.cornerRadius() 属性吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-01
    • 2022-11-30
    • 1970-01-01
    相关资源
    最近更新 更多