组合动画


-(void)deleteWithAnimations:(CGRect)destinationFrame

{

    CALayer *layer =[CALayer layer];

    layer.bounds = CGRectMake(0, 0, 100, 100);

    layer.contents = (__bridge id)([[self renderSnapshotWithMarginForAxis] CGImage]);

    [layer setShadowPath:[UIBezierPath bezierPathWithRect:[layer bounds]].CGPath];

    [layer setShadowOpacity:0.8];

    [layer setShadowOffset:CGSizeMake(5.0, 5.0)];

    [self.layer addSublayer:layer];

    

    //贝塞尔曲线路径

    UIBezierPath *movePath = [UIBezierPath bezierPath];

    [movePath moveToPoint:CGPointMake(0, self.frame.size.height)];

    [movePath addQuadCurveToPoint:CGPointMake(destinationFrame.origin.x,destinationFrame.origin.y) controlPoint:CGPointMake(300, 100)];

    

    //以下必须导入QuartzCore

    //关键帧动画(位置)

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

    posAnim.path = movePath.CGPath;

    posAnim.removedOnCompletion = YES;

    

    //缩放动画

    CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];

    scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];

    scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.01, 0.01, 1.0)];

    scaleAnim.removedOnCompletion = YES;

    

    //旋转动画

    CABasicAnimation *rotateAnim = [CABasicAnimation animationWithKeyPath:@"transform"];

    rotateAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];

    rotateAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(-45/M_PI, 0.0, 0, 1)];

    rotateAnim.removedOnCompletion = NO;

    

    //透明动画

    CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];

    opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];

    opacityAnim.toValue = [NSNumber numberWithFloat:0.1];

    opacityAnim.removedOnCompletion = YES;

    

    //动画组

    CAAnimationGroup *animGroup = [CAAnimationGroup animation];

    animGroup.animations = [NSArray arrayWithObjects:posAnim, scaleAnim,rotateAnim, opacityAnim, nil];

    animGroup.duration = 1;

    [layer addAnimation:animGroup forKey:nil];

}


- (UIImage *) renderSnapshotWithMarginForAxis

{

    CGSize contextSize = self.frame.size;

    CGFloat xOffset = 0.0f;

    CGFloat yOffset = 0.0f;

    

   

    contextSize.width += 2.0*10;

    

    

    UIGraphicsBeginImageContextWithOptions(contextSize, NO, 0.0); // if you want to see border added for antialiasing pass YES as second param

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextTranslateCTM(context, xOffset, yOffset);

    

    [self.layer renderInContext:context];

    

    UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    return snapshot;

}

你可能感兴趣的:(组合动画)