Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)highlightButton:(UIButton*)button withDuration:(CGFloat)duration {
- UIImage* image = [button imageForState:UIControlStateNormal];
- UIGraphicsBeginImageContext(image.size);
- CGContextRef context = UIGraphicsGetCurrentContext();
- UIGraphicsPushContext(context);
- [image drawAtPoint:CGPointZero];
- [[UIColor colorWithWhite:1.0 alpha:1.0] set];
- UIRectFillUsingBlendMode(CGRectMake(0, 0, image.size.width, image.size.height), kCGBlendModeSourceIn);
- UIGraphicsPopContext();
- UIImage* mask = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- //Add the mask on top of the source button
- UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,
- button.frame.size.width, button.frame.size.height)];
- imageView.image = mask;
- imageView.alpha = 0.0;
- [button addSubview:imageView];
- CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
- anim.fromValue = [NSNumber numberWithFloat:0.0];
- anim.toValue = [NSNumber numberWithFloat:0.5];
- anim.repeatCount = 2;
- anim.autoreverses = YES;
- anim.duration = duration/(anim.repeatCount*2);
- [imageView.layer addAnimation:anim forKey:@"opacity"];
- [imageView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:(anim.repeatCount*anim.duration*2)+.2];
- [imageView release];
- }
Add Comment
Please, Sign In to add comment