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

ios-动画组

2015-09-30 14:28 543 查看
9.30 动画组

CAAnimationGroup

/*

 CAAnimationGroup

 1、动画的数组 animations

 2、启动的时间 beginTime

 

 动画组设置了持续时间  可能就会导致动画组里面的某一个动画的 持续时间 没响应(失效)

 */

#import "ViewController.h"

@interface ViewController ()

{

    CALayer *petal;

}

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    [self addBgView];

    [self addPetaller];

    [self addAnimationGroup];

    

    

}

- (CAKeyframeAnimation *)dropAnimation

{

    CAKeyframeAnimation *drop = [CAKeyframeAnimation animationWithKeyPath:@"position"];

    CGMutablePathRef pathRef = CGPathCreateMutable();//创建路径

    CGPathMoveToPoint(pathRef, NULL, petal.position.x, petal.position.y);

    //CGPathAddCurveToPoint cp1x y cpx y 设置两个点 在这两个点之间取画曲线

    //<#CGFloat x#> <#CGFloat y#>  终止点

    CGPoint endPoint = CGPointMake(80, 500);

    CGPathAddCurveToPoint(pathRef, NULL, 160, 280,-30 , 300,
endPoint.x, endPoint.y);

    drop.path = pathRef;

    CGPathRelease(pathRef);

    

    return drop;

}

- (CABasicAnimation *)rotationAnimation

{

    CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    rotation.toValue = @(M_PI_2*3);

    rotation.removedOnCompletion = YES;

    

    return rotation;

}

#pragma mark -----添加动画数组-----

- (void)addAnimationGroup

{

    //初始化分组动画

    CAAnimationGroup *group = [CAAnimationGroup animation];

    group.animations = @[[self rotationAnimation],[self dropAnimation]];

    group.duration = 5;

    //beginTime 动画开始的时间(10秒之后,延迟加载)

    //CACurrentMediaTime  获得当前的时间

    //从调用这个方法开始  10秒 之后 执行动画

    group.beginTime = CACurrentMediaTime() + 1;

    

    group.removedOnCompletion = NO;

    group.fillMode = kCAFillModeBoth;

    

    [petal addAnimation:group forKey:@"group"];

}

- (void)addPetaller

{

    UIImage *image = [UIImage imageNamed:@"petal.jpg"];

   petal = [[CALayer alloc]init];

    petal.position = CGPointMake(100, 200);

    petal.bounds = CGRectMake(0, 0,
image.size.width, image.size.height);

    petal.contents = (id)image.CGImage;

    [self.view.layer addSublayer:petal];

    

}

- (void)addBgView

{

    UIImageView *bgImgView = [[UIImageView alloc]initWithFrame:self.view.frame];

    bgImgView.image = [UIImage imageNamed:@"C7QB825$S`(D65_TTRBBX@1.jpg"];

    [self.view addSubview:bgImgView];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios 动画