zoukankan      html  css  js  c++  java
  • IOS动画(4)动画组

    动画组CAAnimationGroup的使用十分简单,核心想法是把多个动画效果组合起来,各个动画效果并行处理,这些动画效果可以是CABasicAnimation,也可以是CAKeyframeAnimation

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        CALayer *layer = [CALayer layer];
        layer.bounds = CGRectMake(0, 0, 120, 120);
        layer.position = CGPointMake(60, 100);
        layer.cornerRadius = 60;
        layer.masksToBounds = YES;
        layer.contents = (id)[UIImage imageNamed:@"5.png"].CGImage;
        [self.view.layer addSublayer:layer];
    
    }
    
    
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    
        CALayer *layer = [self.view.layer.sublayers lastObject];
    
        
        //自转动画
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
        animation.toValue = @M_PI;
        animation.autoreverses = YES;
        animation.duration = 1;
        
        
        //绕矩阵旋转动画
        CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        
        CGPathRef path = CGPathCreateMutable();
        CGPathAddRect(path, &CGAffineTransformIdentity, CGRectMake(layer.position.x, layer.position.y, 200, 300));
        keyFrameAnimation.path = path;
        keyFrameAnimation.duration = 2;
        CGPathRelease(path);
        
        //创建动画组,包含前面两种动画
        CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
        animationGroup.animations = @[animation,keyFrameAnimation];
        animationGroup.duration = 2;
        animationGroup.repeatCount = HUGE_VALF;
        
        [layer addAnimation:animationGroup forKey:nil];
        
        
    }

     上面代码实现的效果是图片边自转边绕矩形路径转圈

  • 相关阅读:
    Codeforces Round #274 (Div. 2)
    codeforces 477C
    ZOJ 3822 Domination
    Codeforces Round #271 (Div. 2)
    进程
    线程
    udp和tcp特点 实现文件上传
    面向对象补1
    socket基本语法和粘包
    网络编程
  • 原文地址:https://www.cnblogs.com/zanglitao/p/4047701.html
Copyright © 2011-2022 走看看