Created
March 10, 2016 09:18
-
-
Save ltebean/943c5549214729e196e3 to your computer and use it in GitHub Desktop.
mask layer animation
This file contains hidden or 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
let rect = CGRectMake(10, 10, 30, 30) | |
let extremePoint = CGPoint(x: CGRectGetWidth(view.bounds), y: CGRectGetHeight(view.bounds)) | |
let circleMaskPathInitial = UIBezierPath(ovalInRect: CGRectMake(10, 10, 30, 30)) | |
let radius = sqrt((extremePoint.x * extremePoint.x) + (extremePoint.y * extremePoint.y)) | |
let circleMaskPathFinal = UIBezierPath(ovalInRect: CGRectInset(rect, -radius, -radius)) | |
let maskLayer = CAShapeLayer() | |
maskLayer.path = circleMaskPathInitial.CGPath | |
view.layer.mask = maskLayer | |
let animation = CABasicAnimation(keyPath: "path") | |
animation.fromValue = circleMaskPathInitial.CGPath | |
animation.toValue = circleMaskPathFinal.CGPath | |
animation.duration = 3 | |
animation.delegate = self | |
maskLayer.addAnimation(animation, forKey: "path") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment