自定义动画CABasicAnimation
来源:互联网 发布:电脑双肩包 知乎 编辑:程序博客网 时间:2024/06/05 12:42
#import "TestViewController.h"@interface TestViewController ()@property (nonatomic, strong)NSNumber *index;@property (nonatomic ,strong)NSMutableArray *recycleArray;@end@implementation TestViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];//控制开关按钮 btn.top = 70 ; btn.left =70; [btn addTarget:self action:@selector(test2) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; [self test1];}- (void)test1{ _recycleArray = [NSMutableArray array]; CGPoint FirstPonit = CGPointMake(self.view.centerX, self.view.centerY-20); NSArray *arraySize = @[NSStringFromCGSize(CGSizeMake(self.view.width/4, self.view.width/4)),NSStringFromCGSize(CGSizeMake(60, 60)),NSStringFromCGSize(CGSizeMake(40,40 )),NSStringFromCGSize(CGSizeMake(20, 20)),NSStringFromCGSize(CGSizeMake(80, 80))]; NSArray *arrayPoint = @[NSStringFromCGPoint(FirstPonit),NSStringFromCGPoint(CGPointMake(FirstPonit.x+90, FirstPonit.y-70)),NSStringFromCGPoint(CGPointMake(FirstPonit.x-90 , FirstPonit.y-95)),NSStringFromCGPoint(CGPointMake(FirstPonit.x+90 , FirstPonit.y+90)),NSStringFromCGPoint(CGPointMake(FirstPonit.x-90 , FirstPonit.y+90))]; for (int i = 0; i<5; i++) { CGSize size = CGSizeFromString(arraySize[i]); CGPoint point = CGPointFromString(arrayPoint[i]); UIView *view = [[UIView alloc] init]; view.size = size; view.centerX = point.x; view.centerY = point.y; view.layer.cornerRadius = view.width/2; switch (i) { case 0: { view.backgroundColor = [UIColor redColor]; } break; case 1: { view.backgroundColor = [UIColor grayColor]; } break; case 2: { view.backgroundColor = [UIColor greenColor]; } break; case 3: { view.backgroundColor = [UIColor orangeColor]; } break; case 4: { view.backgroundColor = [UIColor blackColor]; } break; default: break; } [self.recycleArray addObject:view]; [self changeTheView:view Point:CGPointFromString(arrayPoint[i])]; }}- (void)changeTheView:(UIView*)view Point:(CGPoint)point{ CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; animation.fromValue = [NSNumber numberWithFloat:0.01]; animation.toValue = [NSNumber numberWithFloat:1]; CABasicAnimation *move = [CABasicAnimation animationWithKeyPath:@"position"]; move.fromValue = [NSValue valueWithCGPoint:CGPointMake(self.view.width/2, self.view.height/2-20)]; move.toValue = [NSValue valueWithCGPoint:point]; CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; opacityAnimation.fromValue = [NSNumber numberWithFloat:0.1]; opacityAnimation.toValue = [NSNumber numberWithFloat:1.0]; CAAnimationGroup *group = [CAAnimationGroup animation]; group.duration = 1;//它设定开始值到结束值花费的时间 group.repeatCount = 1;//默认的是 0,意味着动画只会播放一次。如果指定一个无限大的重复次数,使用 1e100f group.autoreverses = NO;//当你设定这个属性为 YES 时,在它到达目的地之后,动画的返回到开始的值,代替了直接跳转到 开始的值。 group.removedOnCompletion = NO; group.fillMode = kCAFillModeForwards; group.animations = @[animation,move,opacityAnimation]; [view.layer addAnimation:group forKey:@"aaa"];}- (void)test2{ self.index = 0;}-(void)setIndex:(NSNumber*)index{ _index = index; NSInteger time = [index integerValue]; if (time <5) { dispatch_async(dispatch_get_main_queue(), ^{ [self.view addSubview:_recycleArray[time]]; }); time ++; [self performSelector:@selector(setIndex:) withObject:[NSNumber numberWithInteger:time] afterDelay:1];//每一秒调用方法 }}
0 0
- 自定义动画CABasicAnimation
- CABasicAnimation 动画
- CABasicAnimation 动画
- CABasicAnimation 动画
- CABasicAnimation 动画
- CABasicAnimation 动画
- CABasicAnimation动画
- CABasicAnimation动画
- CABasicAnimation:动画
- CABasicAnimation 基本动画学习
- CABasicAnimation动画的解析
- CABasicAnimation 基本动画学习
- CABasicAnimation 基本动画学习
- CABasicAnimation 基本动画学习
- CABasicAnimation 热门动画效果
- CABasicAnimation 动画效果
- CABasicAnimation 基本动画学习
- 动画CATransition、CABasicAnimation
- Hadoop 元模式之作业归并
- iOS NSCondition结合代码以及项目进行详解
- [NOIP 2013]转圈游戏 快速幂
- Rabbitmq队列高可用的策略
- java中的快速排序实现
- 自定义动画CABasicAnimation
- elasticsearch学习步骤01--------简单介绍
- Spring-注解配置
- Ubuntu 12.04 在root登陆之后没有声音的解决方法
- 平摊分析(算法导论)
- 植物模型
- 在 Linux 上安装 PostgreSQL
- 我的JAVA之路(二)
- java连接各大数据的方法