动画特效之动画组

#import "ViewController.h"

@interface ViewController ()
{
    CALayer *layer;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    /*
     CAAnimationGroup的属性是:
     1、动画的数组 animations
     2、启动时间:beginTime

     动画组设置持续时间(duration) 可能会导致动画组里面的动画持续时间失效

     */


    UIImageView *bgimageView = [[UIImageView alloc]initWithFrame:self.view.frame];
    bgimageView.image = [UIImage imageNamed:@"1.jpg"];
    [self.view addSubview:bgimageView];


    [self addFollower];

    [self addAnimationGroup];

}

- (void)addFollower{
    UIImage *image = [UIImage imageNamed:@"2"];
    layer = [[CALayer alloc]init];
    layer.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
    layer.position = CGPointMake(100, 200);
    layer.contents = (id)(image.CGImage);

    [self.view.layer addSublayer:layer];
}
#pragma mark  添加动画组
- (void)addAnimationGroup{
    CAAnimationGroup *Group = [[CAAnimationGroup alloc]init];
    Group.animations = @[/*具体的动画*/[self rotationAnimation],[self dropAnimation]];
//    添加到layer中
    Group.duration = 10;
//    beginTime动画开始的时间
//    从调用这个方法开始  10秒后执行动画
    Group.beginTime = CACurrentMediaTime()+5;//CACurrentMediaTime获得当前时间,来自于继承中的属性
    Group.removedOnCompletion = NO;
    Group.fillMode = kCAFillModeBoth;
    [layer addAnimation:Group forKey:@"Group"];
}
#pragma mark 花瓣旋转
- (CABasicAnimation *)rotationAnimation{
    CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotation.toValue = @(M_PI_2*3);//旋转
    rotation.removedOnCompletion = NO;

    return rotation;
}
#pragma mark 掉落的路径
- (CAKeyframeAnimation *)dropAnimation{
    CAKeyframeAnimation *drop = [CAKeyframeAnimation animationWithKeyPath:@"position"];
//    创建路径
    CGMutablePathRef ref = CGPathCreateMutable();
    CGPathMoveToPoint(ref, NULL, layer.position.x, layer.position.y);
//    设置两个点,在这两个点之间去画曲线cp1和cp2   x,y是终止点
    CGPoint endPoint = CGPointMake(80, 580);
    CGPathAddCurveToPoint(ref, NULL, 160, 280, -30, 300, endPoint.x, endPoint.y);
    drop.path = ref;
    CGPathRelease(ref);//释放
    return drop;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值