• 关键帧动画


    /*
    CAKeyframeAnimation 也属于 CAPropertyAnimation 
     关键帧动画  可以让我们精准是控制动画效果 它的原理是把动画序列里面比较关键的帧提取出来 设置他的动画效果
     
     path属性 执行动画轨迹的路径
     values 执行动画轨迹是数组
     
    */
    
    
    #import "ViewController.h"
    
    @interface ViewController ()
    {
    //    UIImage *image;
        CALayer *heartLayer;
    //    CALayer *myLayer;
    }
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        [self addHeart];
    }
    
    - (void)addHeart{
        
        UIImage *image = [UIImage imageNamed:@"桃心"];
        
        heartLayer = [[CALayer alloc]init];
        heartLayer.position = CGPointMake(self.view.center.x, 200);
        heartLayer.bounds = CGRectMake(0, 0, image.size.width/5, image.size.height/5);
        heartLayer.contents = (id)image.CGImage;
        
        [self.view.layer addSublayer:heartLayer];
    }
    
    - (void)addAnimation{
    //    CAKeyframeAnimation 关键帧动画的类
        CAKeyframeAnimation *drow = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        drow.duration = 0.001;
        drow.repeatCount = HUGE;
        drow.values = @[[self getPointWithX:0 andY:0],[self getPointWithX:50 andY:-50],[self getPointWithX:100 andY:-65],[self getPointWithX:120 andY:-50],[self getPointWithX:160 andY:0],[self getPointWithX:120 andY:100],[self getPointWithX:50 andY:150],[self getPointWithX:0 andY:200],[self getPointWithX:-50 andY:150],[self getPointWithX:-120 andY:100],[self getPointWithX:-160 andY:0],[self getPointWithX:-120 andY:-50],[self getPointWithX:-100 andY:-65],[self getPointWithX:-50 andY:-50],[self getPointWithX:0 andY:0]];
        
        [heartLayer addAnimation:drow forKey:@"move"];
        
    }
    #pragma mark-----把CGPoint 转换成NSValue--------
    - (NSValue *)getPointWithX:(CGFloat)x andY:(CGFloat)y{
        
        return [NSValue valueWithCGPoint:CGPointMake(x+heartLayer.position.x, y+heartLayer.position.y)];
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
        [self addAnimation];
    }
  • 相关阅读:
    修复ecshop商品重量BUG小数位增至五位
    ECSHOP 支付宝发货确认接口,记录支付宝返回的交易号
    php数字补零的两种方法
    PHP获取当前时间的毫秒数(yyyyMMddHHmmssSSS)
    ajax 设置Access-Control-Allow-Origin实现跨域访问
    MySQL Master High Available 源码篇
    MHA 报错:There is no alive slave. We can't do failover
    cdid
    mha error
    mysql relay log参数汇总
  • 原文地址:https://www.cnblogs.com/liYongJun0526/p/4874142.html
Copyright © 2020-2023  润新知