您的位置:首页 > 移动开发 > IOS开发

IOS 雷达效果(Layer的动画)笔记

2014-06-18 14:45 423 查看
//
//  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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: