各种动画效果

1.给定圆心,围绕圆心来转动

UIView *anmicationView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 4, 4)];

    anmicationView.backgroundColor = [UIColor redColor];

    [self.view addSubview:anmicationView];

    

    CAKeyframeAnimation *orbitAnimation = [CAKeyframeAnimation animation];

    orbitAnimation.keyPath = @"position";

    

    //创建一个圆形的 CGPath 作为我们的关键帧动画的 path

    orbitAnimation.path = CFAutorelease(CGPathCreateWithEllipseInRect(CGRectMake(20, 100, 72, 72), NULL));

    orbitAnimation.duration = .9;

    orbitAnimation.additive = YES;

    orbitAnimation.repeatCount = HUGE_VALF;

    

    //使用 calculationMode 是控制关键帧动画时间的另一种方法。我们通过将其设置为 kCAAnimationPaced,让 Core Animation 向被驱动的对象施加一个恒定速度,不管路径的各个线段有多长。将其设置为 kCAAnimationPaced 将无视所有我们已经设置的 keyTimes

    orbitAnimation.calculationMode = kCAAnimationPaced;

    //确保view沿着路径旋转

    orbitAnimation.rotationMode = kCAAnimationRotateAuto;

    

    

    

    [anmicationView.layer addAnimation:orbitAnimation forKey:@"test"];

 

2.自己沿着自己的圆心自传

UIView *animationView = [[UIView alloc] initWithFrame:CGRectMake(10, 100, 10, 10)];

    [self.view addSubview:animationView];

    CABasicAnimation* rotationAnimation;

    animationView.backgroundColor = [UIColor redColor];

    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];

    rotationAnimation.duration = 1;

    rotationAnimation.cumulative = YES;

    rotationAnimation.repeatCount = HUGE_VALF;

    

    [animationView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

3.沿着特定的点,联系来的路径来执行动画效果

UIView *anmicationViews = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 4, 4)];

    anmicationViews.backgroundColor = [UIColor redColor];

    [self.view addSubview:anmicationViews];

    

    CGMutablePathRef path = CGPathCreateMutable();  //初始创建路线

    CGPathMoveToPoint(path, NULL, 40, 80);   //路线起点

    CGPathAddLineToPoint(path, NULL,80 , 150);   //连线到第二个点

    CGPathAddLineToPoint(path, NULL,100 , 90);   //连线到第三个点

    CGPathAddLineToPoint(path, NULL, 200, 200);

    CGPathCloseSubpath(path);  //路线close起来,即让第三个点和第一个点自动连接

    

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

    theAnimation.path = path;  //动画路线

    theAnimation.duration = .5;  //动画总时间

    theAnimation.repeatCount = HUGE_VALF;//时间的最大值

    CFRelease(path);

    [anmicationViews.layer addAnimation:theAnimation forKey:@"position"]; //让动画的执行者开始执行动画

转载于:https://www.cnblogs.com/nhwly/articles/3881551.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值