Skip to content

Instantly share code, notes, and snippets.

@ltebean
Created March 10, 2016 09:18
Show Gist options
  • Save ltebean/943c5549214729e196e3 to your computer and use it in GitHub Desktop.
Save ltebean/943c5549214729e196e3 to your computer and use it in GitHub Desktop.
mask layer animation
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