美文网首页
毛玻璃效果和简单的动画

毛玻璃效果和简单的动画

作者: 别叫我超人 | 来源:发表于2016-05-30 14:32 被阅读263次

    1.毛玻璃效果 (iOS8之后) 

    iOS8之后新加了UIBlurEffect类和UIVisualEffectView类使用起来也很简单 

    UIBlurEffect类设定毛玻璃效果的类型(3中类型)

    UIVisualEffectView类在创建时加入UIBlurEffect的类的对象

    2.系统自带的uiview的block块

    一个简单的图片视图的放大然后渐渐消失的动画最后移除视图 可以使用嵌套block块来实现

    3.CALayer层的动画

    CABasicAnimation一般用法通过fromValue和toValue来指定开始和结束的值

    属性Autoreverses 当设为YES时,在它到达目的地后,动画回到原始的值,代替直接跳转到开始的值

    Duration 动画的时长  repeatCount 动画的重复次数(默认为0)只走一次。

    Speed 动画播放按照默认的速度播放 默认为1.0 如果改变它的值会影响到动画的持续时间。

    RemovedOnCompletion 设为YES在指定时间内动画完成后,动画从层上移除

    animationWithKeyPath的值:

    transform.scale 缩放 

    transform.translation.y 纵向移动

    transform.translation.x 横向移动

    opacity 透明度

    transform.rotation.z 旋转

    backgroundColor 背景色变化

    +(CABasicAnimation *)opacityForever_Animation:(float)time //永久闪烁的动画

    {

    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"opacity"];

    animation.fromValue=[NSNumber numberWithFloat:1.0];

    animation.toValue=[NSNumber numberWithFloat:0.0];

    animation.autoreverses=YES;

    animation.duration=time;

    animation.repeatCount=FLT_MAX;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    return animation;

    }

    +(CABasicAnimation *)opacityTimes_Animation:(float)repeatTimes durTimes:(float)time; //有闪烁次数的动画

    {

    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"opacity"];

    animation.fromValue=[NSNumber numberWithFloat:1.0];

    animation.toValue=[NSNumber numberWithFloat:0.4];

    animation.repeatCount=repeatTimes;

    animation.duration=time;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

    animation.autoreverses=YES;

    return  animation;

    }

    +(CABasicAnimation *)moveX:(float)time X:(NSNumber *)x //横向移动

    {

    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];

    animation.toValue=x;

    animation.duration=time;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    return animation;

    }

    +(CABasicAnimation *)moveY:(float)time Y:(NSNumber *)y //纵向移动

    {

    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];

    animation.toValue=y;

    animation.duration=time;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    return animation;

    }

    +(CABasicAnimation *)scale:(NSNumber *)Multiple orgin:(NSNumber *)orginMultiple durTimes:(float)time Rep:(float)repeatTimes //缩放

    {

    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.scale"];

    animation.fromValue=orginMultiple;

    animation.toValue=Multiple;

    animation.duration=time;

    animation.autoreverses=YES;

    animation.repeatCount=repeatTimes;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    return animation;

    }

    +(CAAnimationGroup *)groupAnimation:(NSArray *)animationAry durTimes:(float)time Rep:(float)repeatTimes //组合动画

    {

    CAAnimationGroup *animation=[CAAnimationGroup animation];

    animation.animations=animationAry;

    animation.duration=time;

    animation.repeatCount=repeatTimes;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    return animation;

    }

    +(CAKeyframeAnimation *)keyframeAniamtion:(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;

    }

    CAKeyFrameAnimation 关键帧动画 values属性指明整个动画过程中的关键帧点

    path和values作用一样 指定整个动画经过的路径 当values和path同时指定时,values属性会被忽略。

    keyTimes 指定一个数组用来为每一个路径指定动画时间如果没有设置keyTimes,系统默认每一个路径的时间为:time = duration/(values.count - 1),每一个路径的时间相。如果设置路径的动画时间不一致时可以传入一个数组 数组的首尾为0和1 如 animation.keyTimes = @[[NSNumber numberWithFloat:0.0],[NSNumber numberWithFloat:0.2],[NSNumber numberWithFloat:0.4],[NSNumber numberWithFloat:0.8],[NSNumber numberWithFloat:1.0]];那么第一段动画时长为(0.2-0.0)* duration,第二段为(0.4-0.2)*duration 依次计算动画时长。

    timeFunctions用以指定时间函数,类似与运动的加速度

    kCAMediaTimingFunctionLinear//线性

     kCAMediaTimingFunctionEaseIn//淡入

     kCAMediaTimingFunctionEaseOut//淡出

     kCAMediaTimingFunctionEaseInEaseOut//淡入淡出

     kCAMediaTimingFunctionDefault//默认

    calculationMode来决定每一个子路径运动的类型

    kCAAnimationLinear//默认,线性

     kCAAnimationDiscrete//离散,无中间过程,但keyTimes设置的时间依旧生效,物体跳跃地出现在各个关键帧上

     kCAAnimationPaced//平均,keyTimes跟timeFunctions失效

     kCAAnimationCubic//平均,同上

     kCAAnimationCubicPaced//平均,同上

    相关文章

      网友评论

          本文标题:毛玻璃效果和简单的动画

          本文链接:https://www.haomeiwen.com/subject/ouoqdttx.html