IOS layer常用动画

项目中总是需要用到一些动画效果

代码复制过来复制过去找起来很麻烦,直接粘上来以后好找。有的是网上找的,时间久了已经记不得出处了。有人知道就帮忙说下,我好粘帖下别人的链接。

1.过度动画 就是view的渐变效果,偷懒经常使用渐变效果。

#pragma mark - 过度动画

-(void) GuoDuAnimation:(UIView *)view
{
    CATransition *animation = [CATransition animation];
    
    animation.duration = 0.5;
    
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    
    animation.type = @"Fade";
    
    animation.subtype = kCATransitionFromLeft;
    
    [view.layer addAnimation:animation forKey:nil];
    /*
     suckEffect(三角)
     
     rippleEffect(水波抖动)
     
     pageCurl(上翻页)
     
     pageUnCurl(下翻页)
     
     oglFlip(上下翻转)
     */
}

2.移动动画

#pragma mark ===== 横向、纵向移动 ===========

-( CABasicAnimation *)moveX:( float )time X:( NSNumber *)x

{
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath : @"transform.translation.x" ]; ///.y 的话就向下移动。
    
    animation. toValue = x;
    
    animation. duration = time;
    
    animation. removedOnCompletion = NO ; //yes 的话,又返回原位置了。
    
    animation. repeatCount = MAXFLOAT ;
    
    animation. fillMode = kCAFillModeForwards ;
    
    return animation;
    
}

3.闪烁动画

#pragma mark === 永久闪烁的动画 ======

-(CABasicAnimation *)opacityForever_Animation:( float )time
{
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath : @"opacity" ]; // 必须写 opacity 才行。
    
    animation. fromValue = [NSNumber numberWithFloat : 1.0f ];
    
    animation. toValue = [NSNumber numberWithFloat : 0.0f ]; // 这是透明度。
    
    animation. autoreverses = YES ;
    
    animation. duration = time;
    
    animation. repeatCount = MAXFLOAT ;
    
    animation. removedOnCompletion = NO ;
    
    animation. fillMode = kCAFillModeForwards ;
    
    animation. timingFunction =[CAMediaTimingFunction functionWithName : kCAMediaTimingFunctionEaseIn ]; /// 没有的话是均匀的动画。
    
    return animation;
    
}

4.缩放动画

#pragma mark ===== 缩放 -=============

-( CABasicAnimation *)scale:( NSNumber *)Multiple orgin:( NSNumber *)orginMultiple durTimes:( float )time Rep:( float )repertTimes

{
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath : @"transform.scale" ];
    
    animation. fromValue = Multiple;
    
    animation. toValue = orginMultiple;
    
    animation. autoreverses = YES ;
    
    animation. repeatCount = repertTimes;
    
    animation. duration = time; // 不设置时候的话,有一个默认的缩放时间 .
    
    animation. removedOnCompletion = NO ;
    
    animation. fillMode = kCAFillModeForwards ;
    
    return   animation;
    
}

5.组合动画

#pragma mark ===== 组合动画 -=============

-( CAAnimationGroup *)groupAnimation:(NSArray *)animationAry durTimes:(float)time Rep:(float)repeatTimes

{
    
    CAAnimationGroup *animation = [CAAnimationGroup animation];
    
    animation. animations = animationAry;
    
    animation. duration = time;
    
    animation. removedOnCompletion = NO ;
    
    animation. repeatCount = repeatTimes;
    
    animation. fillMode = kCAFillModeForwards ;
    
    return animation;
    
}

6.路径动画

#pragma mark ===== 路径动画 -=============

-( CAKeyframeAnimation *)keyframeAnimation:(CGMutablePathRef )path durTimes:(float)time Rep:(float)repeatTimes

{
    
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath : @"position" ];
    
    animation. path = path;
    
    animation. removedOnCompletion = NO ;
    
    animation. fillMode = kCAFillModeForwards ;
    
    animation. timingFunction = [CAMediaTimingFunction functionWithName : kCAMediaTimingFunctionEaseIn ];
    
    animation. autoreverses = NO ;
    
    animation. duration = time;
    
    animation. repeatCount = repeatTimes;
    
    return animation;
    
}

7.旋转动画

#pragma mark ==== 旋转动画 ======

-( CABasicAnimation *)rotation:( float )dur degree:( float )degree direction:( int )direction repeatCount:( int )repeatCount

{
    
    CATransform3D rotationTransform = CATransform3DMakeRotation (degree, 0 , 0 , direction);
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath : @"transform" ];
    
    animation. toValue = [ NSValue valueWithCATransform3D :rotationTransform];
    
    animation. duration   =  dur;
    
    animation. autoreverses = NO ;
    
    animation. cumulative = NO ;
    
    animation. fillMode = kCAFillModeForwards ;
    
    animation. repeatCount = repeatCount;
    
    animation. delegate = self ;
    
    return animation;
    
}

后续有用的再添加...

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值