组合动画


-(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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值