关键帧动画

作者: 我的梦想之路 | 来源:发表于2016-07-08 19:18 被阅读34次
CALayer *transitionLayer = [[CALayer alloc] init];

 //开启一个动画事务
    [CATransaction begin];
    
    //CATransaction 事务类,可以对多个layer的属性同时进行修改.它分隐式事务,和显式事务.kCATransactionDisableActions
    [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
    transitionLayer.opacity = 0.6;
    //contents是layer的一个属性
    
    UIImageView *tempimgview;
    for (UIView *aView in [picView subviews]) // picView代表需要执行动画的视图
    {
        if([aView isKindOfClass:[UIImageView class]]){
            //NSLog(@"=====找到imageview");
            tempimgview = (UIImageView*)aView;
            break;
        }
        
    }
//设置CALayer的内容
transitionLayer.contents = (id)tempimgview.layer.contents;

//父类不同,所以需要坐标系统的转换,必须是处于同一window内
    transitionLayer.frame = [[UIApplication sharedApplication].keyWindow convertRect:tempimgview.bounds fromView:tempimgview];
    
    [[UIApplication sharedApplication].keyWindow.layer addSublayer:transitionLayer];
   
    [UIView beginAnimations:@"imageViewAnimation" context:(__bridge void *)(tempimgview)];
/// 提交事务
    [CATransaction commit];

//路径曲线:贝塞尔曲线,使动画按照你所设定的贝塞尔曲线运动
    UIBezierPath *movePath = [UIBezierPath bezierPath];
    [movePath moveToPoint:transitionLayer.position];
    
    //传入购物车的坐标(X,Y)
    CGPoint toPoint = CGPointMake(self.view.frame.size.width-20, 40);
    //
    [movePath addQuadCurveToPoint:toPoint
                     controlPoint:CGPointMake(self.view.frame.size.width-50,transitionLayer.position.y-50)];
    
    
    //关键帧
    CAKeyframeAnimation *positionAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    positionAnimation.path = movePath.CGPath;
    positionAnimation.removedOnCompletion = YES;
    
   
    
    //缩小动画
    CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
    scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
    scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
    //缩小动画结束移除
    scaleAnim.removedOnCompletion = YES;
    NSLog(@"=====in enjoy55555");
    
    //将抛物动画和缩小动画加入动画组,可以执行多个动画,并且设置动画的执行时间
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.beginTime = CACurrentMediaTime();
    group.duration = 0.7;
    group.animations = [NSArray arrayWithObjects:positionAnimation,scaleAnim,nil];
    group.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    //group.fillMode = kCAFillModeForwards;
    group.removedOnCompletion = YES;
    group.autoreverses= NO;
    group.delegate=self;
    [transitionLayer addAnimation:group forKey:@"opacity"];
静止界面 动画开始 动画执行 动画执行

相关文章

  • HTML5动画

    关键帧动画 实现代码: 关键帧动画 *{ margin: 0; padding: ...

  • 抛物动画

    此动画在于运用 CAKeyframeAnimation 关键帧动画,以及贝塞尔关键帧动画 - (void)thro...

  • 前端——anmiation

    animation:;动画 设定动画方案:设定“关键帧”。 动画关键帧写在其他应用样式之前,当关键帧前用百分比表示...

  • iOS Animation创建及使用

    iOS 实现的基本动画 头尾式动画 2.block动画的方法 iOS显示关键帧动画 关键帧动画 动画的创建和使用 ...

  • CAKeyframeAnimation 关键帧动画

    CAKeyframeAnimation(关键帧动画) 关键帧动画就是在动画控制过程中开发者指定主要的动画状态,至于...

  • iOS 动画十:Layer Keyframe Animation

    Layer 上的 Keyframe 动画与 UIView 上的关键帧动画有些不同。UIView 关键帧动画是将独立...

  • Unity常见面试题(二)

    111. [动画系统]如何将其他类型的动画转换成关键帧动画? 动画->点缓存->关键帧 112. [动画]Unit...

  • iOS缩放动画

    //缩放动画 CAKeyframeAnimation(关键帧动画) //UIView动画方式

  • CAKeyframeAnimation

    关键帧动画

  • Css权威指南(4th,第四版中文翻译)-18.动画

    定义关键帧 Keyframes 主要的语法如下: 下面是几个简单的例子: 设置关键帧动画 动画的命名 关键帧选择器...

网友评论

    本文标题:关键帧动画

    本文链接:https://www.haomeiwen.com/subject/msdrjttx.html