iOS 基础动画的使用

    UIBezierPath *bezierPath1 = [UIBezierPath bezierPath];
    
    [bezierPath1 moveToPoint: CGPointMake(286.5, 611.5)]; //一定要设置 不然底层的CGPathRef找不到起始点,将会崩溃
    [bezierPath1 addCurveToPoint: CGPointMake(322.5, 545.5) controlPoint1: CGPointMake(286.5, 606.5) controlPoint2: CGPointMake(347.5, 601.5)];
    [bezierPath1 addCurveToPoint: CGPointMake(336.5, 460.5) controlPoint1: CGPointMake(297.5, 489.5) controlPoint2: CGPointMake(350.5, 511.5)];
    [bezierPath1 addCurveToPoint: CGPointMake(353.5, 399.5) controlPoint1: CGPointMake(322.5, 409.5) controlPoint2: CGPointMake(340.5, 421.5)];
    [bezierPath1 addCurveToPoint: CGPointMake(322.5, 337.5) controlPoint1: CGPointMake(366.5, 377.5) controlPoint2: CGPointMake(322.5, 337.5)];
    [bezierPath1 addCurveToPoint: CGPointMake(286.5, 292.5) controlPoint1: CGPointMake(322.5, 337.5) controlPoint2: CGPointMake(267.5, 333.5)];
    [bezierPath1 addCurveToPoint: CGPointMake(273.5, 234.5) controlPoint1: CGPointMake(305.5, 251.5) controlPoint2: CGPointMake(273.5, 234.5)];

    //位置动画
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    animation.path = [bezierPath1 CGPath]; //设置animation的path
    //可以单独设置某个动画的时间
    animation.duration = 15.0f;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;

    //透明度动画
    CABasicAnimation * alphAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    alphAnimation.fromValue = @(fromOpacity_);
    alphAnimation.toValue = @(toOpacity_);

    //大小动画
    CABasicAnimation *resizeAnimation = [CABasicAnimation animationWithKeyPath:@"bounds.size"];
    [resizeAnimation setToValue:[NSValue valueWithCGSize:CGSizeMake(40, 40)]];
    resizeAnimation.fillMode = kCAFillModeForwards;
    resizeAnimation.removedOnCompletion = NO;
    resizeAnimation.duration = 0.6;


    //旋转动画
    CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    transformAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    transformAnimation.fromValue = @(0);
    transformAnimation.toValue = @(M_PI_4 * (arc4random()%80  + 30));
    
    
    
    
    //创建动画组
    CAAnimationGroup *animationGroup = [[CAAnimationGroup alloc]init];
    animationGroup.duration = arc4random()%4 + 2;
    animationGroup.animations = @[animation, alphAnimation,resizeAnimation,transformAnimation];
    
    
    
    
    //_demoView为一个UIImageView
    [_demoView.layer addAnimation:animationGroup forKey:nil];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值