//
// LPViewController.m
// LayerDemo
//
// Created by linpeng on 14-6-17.
// Copyright (c) 2014年 linpeng. All rights reserved.
//
#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
IOS 雷达效果(Layer的动画)笔记
最新推荐文章于 2021-08-31 16:11:55 发布