I want to create a view that looks like this:
I figure what I need is a uiview with some sort of mask, I can make a mask in the shape of a circle using a UIBezierpath, however I cannot invert this makes so that it masks everything but the circle. I need this to be a mask of a view and not a fill layer because the view that I intend to mask has a UIBlurEffect on it. The end goal is to animate this UIView overtop of my existing views to provide instruction.
Please note that I am using swift. Is there away to do this? If so, how?
You can use this function to create what you need.
Adjust the
radius
andxOffset
andyOffset
to change the radius and position of the circle.For Swift 3, here is rakeshbs' answer formatted so it returns the UIView needed:
Updated again for Swift 4 & removed a few items to make the code tighter.
Please note that
maskLayer.fillRule
is set differently between Swift 4 and Swift 4.2.A rough breakdown on what is happening:
The following code snippet will call this and place a circle in the middle of the screen with radius of 50:
Which looks like this: