Created
March 23, 2016 08:33
-
-
Save nicolastinkl/b049c3e4ec0e4831c047 to your computer and use it in GitHub Desktop.
ios 雷达效果 水波效果
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
// | |
// | |
#import "LPViewController.h" | |
@interface LPViewController () | |
{ | |
CALayer *sublayer2,*sublayer3; | |
} | |
@end | |
@implementation LPViewController | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
UIView *v = [[UIView alloc] initWithFrame:self.view.frame]; | |
[v setBackgroundColor:[UIColor grayColor]]; | |
v.layer.backgroundColor = [UIColor whiteColor].CGColor; | |
[self.view addSubview:v]; | |
sublayer2 = [CALayer layer]; | |
sublayer2.borderWidth = 0.5f; | |
sublayer2.borderColor = [UIColor redColor].CGColor; | |
sublayer2.frame = CGRectMake(10, 10, 60, 60); | |
sublayer2.cornerRadius = 60/2; | |
sublayer2.position = v.center; | |
sublayer2.backgroundColor = [UIColor greenColor].CGColor; | |
[v.layer addSublayer:sublayer2]; | |
int count = 4; | |
float duration = 4.0; | |
for (int i = 0; i<count; i++) { | |
CALayer *lay = [CALayer layer]; | |
lay.borderWidth = 0.1f; | |
lay.borderColor = [UIColor redColor].CGColor; | |
lay.frame = CGRectMake(10, 10, 60, 60); | |
lay.cornerRadius = lay.frame.size.width/2; | |
lay.position = v.center; | |
[v.layer addSublayer:lay]; | |
CABasicAnimation *scaleAnimation1 = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; | |
scaleAnimation1.fromValue = [NSNumber numberWithFloat:1.0]; | |
scaleAnimation1.toValue = [NSNumber numberWithFloat:10.0]; | |
scaleAnimation1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; | |
CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; | |
opacityAnimation.fromValue = [NSNumber numberWithFloat:1.0]; | |
opacityAnimation.toValue = [NSNumber numberWithFloat:0]; | |
CAAnimationGroup *animationGroup = [CAAnimationGroup animation]; | |
animationGroup.fillMode = kCAFillModeBackwards; | |
animationGroup.duration = duration; | |
animationGroup.autoreverses = NO; //是否重播,原动画的倒播 | |
animationGroup.repeatCount = HUGE_VAL;//HUGE_VALF; //HUGE_VALF,源自math.h | |
[animationGroup setAnimations:[NSArray arrayWithObjects:opacityAnimation, scaleAnimation1, nil]]; | |
animationGroup.beginTime = CACurrentMediaTime()+i*duration/count; | |
[lay addAnimation:animationGroup forKey:@"group"]; | |
} | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment