核心动画04——CAAnimationGroup(动画组)
一、
动画组,是CAAnimation的子类,可以保存一组动画对象,将CAAnimationGroup对象加入层后,组中所有动画对象可以同时并发运行
属性说明:
animations:用来保存一组动画对象的NSArray
默认情况下,一组动画对象是同时运行的,也可以通过设置动画对象的beginTime属性来更改动画的开始时间
二、代码
//
// ViewController.m
// 03_UIView71_动画组
//
// Created by 杞文明 on 2017/06/15 22:34:37 星期四
// Copyright © 2017年 杞文明. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//创建动画一
CABasicAnimation *anim1 = [CABasicAnimation animation];
anim1.keyPath = @"position.y";
anim1.toValue = @500;
//创建动画二
CABasicAnimation *anim2 = [CABasicAnimation animation];
anim2.keyPath = @"transform.scale";
anim2.toValue = @0.5;
//创建动画组
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = @[anim1,anim2];
group.duration = 2;
group.removedOnCompletion = NO;
group.fillMode = kCAFillModeForwards;
[self.redView.layer addAnimation:group forKey:nil];
}
@end