Skip to content

Instantly share code, notes, and snippets.

@cemolcay
Last active April 23, 2018 06:17
Show Gist options
  • Save cemolcay/20aa2e3d55b2aa86dbdf to your computer and use it in GitHub Desktop.
Save cemolcay/20aa2e3d55b2aa86dbdf to your computer and use it in GitHub Desktop.
blurred screen with circle mask
@IBOutlet var mapView: MKMapView!
func setupMapBlur () {
var blur: UIView!
if ios8() {
blur = UIVisualEffectView (effect: UIBlurEffect (style: UIBlurEffectStyle.Light))
} else {
blur = FXBlurView (frame: view.frame)
}
blur.frame = view.frame
blur.userInteractionEnabled = false
view.addSubview(blur)
let circleSize: CGFloat = 300
let path = UIBezierPath (
roundedRect: blur.frame,
cornerRadius: 0)
let circle = UIBezierPath (
roundedRect: CGRect (origin: CGPoint (x: blur.center.x - circleSize/2, y: 30),
size: CGSize (width: circleSize, height: circleSize)), cornerRadius: circleSize/2)
path.appendPath(circle)
path.usesEvenOddFillRule = true
let maskLayer = CAShapeLayer ()
maskLayer.path = path.CGPath
maskLayer.fillRule = kCAFillRuleEvenOdd
let borderLayer = CAShapeLayer ()
borderLayer.path = circle.CGPath
borderLayer.strokeColor = UIColor.whiteColor().CGColor
borderLayer.lineWidth = 5
blur.layer.addSublayer(borderLayer)
blur.layer.mask = maskLayer
}
func ios8 () -> Bool {
let version = UIDevice().systemVersion
let major = version.componentsSeparatedByString(".")[0]
if major == "8" {
return true
} else {
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment