How to add a blur mask with a custom shape above a dynamic camera view in Swift?

后端 未结 2 723
孤城傲影
孤城傲影 2021-02-06 13:32

I am using Swift to develop an iOS application with a camera feature, and it requires a blur layer above the camera view with a hole in the middle like the image shown below.

2条回答
  •  甜味超标
    2021-02-06 13:54

    I've done this by creating an overlay with a layer with said blurred image, and then using a mask that is built from a path that goes all the way around the extents, and then jumps to the cutout hole, going the opposite direction with the winding fill rule.

    Refer to documetation here:

    https://developer.apple.com/library/ios/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_paths/dq_paths.html

    There are many documented examples of this though, here is one: drawing with clear color on UIView (cutting a hole) in static method

提交回复
热议问题