Skip to content

Instantly share code, notes, and snippets.

@peterlee0127
Last active August 29, 2015 13:56
Show Gist options
  • Save peterlee0127/9131674 to your computer and use it in GitHub Desktop.
Save peterlee0127/9131674 to your computer and use it in GitHub Desktop.
// Slide to unlock Animation
CALayer *maskLayer = [CALayer layer];
maskLayer.backgroundColor = [[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.55f] CGColor];
maskLayer.contents = (id)[[UIImage imageNamed:@"mask.png"] CGImage];
maskLayer.contentsGravity = kCAGravityCenter;
maskLayer.frame = CGRectMake(self.frame.size.width * -1, 0.0f, self.frame.size.width * 2, self.frame.size.height);
CABasicAnimation *maskAnim = [CABasicAnimation animationWithKeyPath:@"position.x"];
maskAnim.byValue = [NSNumber numberWithFloat:self.frame.size.width];
maskAnim.repeatCount = HUGE_VAL;
maskAnim.duration = 2.0f;
[maskLayer addAnimation:maskAnim forKey:@"slideAnim"];
self.layer.mask = maskLayer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment