Last active
April 23, 2018 06:17
-
-
Save cemolcay/20aa2e3d55b2aa86dbdf to your computer and use it in GitHub Desktop.
blurred screen with circle mask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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