CABasicAnimation用法

来源:互联网 发布:mac os镜像下载 编辑:程序博客网 时间:2024/04/30 06:22

CABasicAnimation用法

Autoreverses

当你设定这个属性为 YES 时,在它到达目的地之后,动画的返回到开始的值,代替了直接跳转到 开始的值。

Duration
Duration 
这个参数你已经相当熟悉了。它设定开始值到结束值花费的时间。期间会被速度的属性所影响。 RemovedOnCompletion
这个属性默认为 YES,那意味着,在指定的时间段完成后,动画就自动的从层上移除了。这个一般不用。

假如你想要再次用这个动画时,你需要设定这个属性为 NO。这样的话,下次你在通过-set 方法设定动画的属 性时,它将再次使用你的动画,而非默认的动画。

Speed

默认的值为 1.0.这意味着动画播放按照默认的速度。如果你改变这个值为 2.0,动画会用 倍的速度播放。 这样的影响就是使持续时间减半。如果你指定的持续时间为 秒,速度为 2.0,动画就会播放秒钟---一半的 持续时间。

BeginTime

这个属性在组动画中很有用。它根据父动画组的持续时间,指定了开始播放动画的时间。默认的是 0.0.组 动画在下个段落中讨论“Animation Grouping”。

TimeOffset

如果一个时间偏移量是被设定,动画不会真正的可见,直到根据父动画组中的执行时间得到的时间都流逝 了。

RepeatCount

默认的是 0,意味着动画只会播放一次。如果指定一个无限大的重复次数,使用 1e100f。这个不应该和 repeatDration 属性一块使用。

RepeatDuration

这个属性指定了动画应该被重复多久。动画会一直重复,直到设定的时间流逝完。它不应该和 repeatCount 一起使用。


animationWithKeyPath的值:

  transform.scale = 比例轉換

    transform.scale.x = 闊的比例轉換

    transform.scale.y = 高的比例轉換

    transform.rotation.z = 平面圖的旋轉

    opacity = 透明度

    margin

    zPosition

    backgroundColor    背景颜色

    cornerRadius    圆角

    borderWidth

    bounds

    contents

    contentsRect

    cornerRadius

    frame

    hidden

    mask

    masksToBounds

    opacity

    position

    shadowColor

    shadowOffset

    shadowOpacity

    shadowRadius


 
+(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;
 
}
 
  
 
+(CABasicAnimation *)movepoint:(CGPoint )point //点移动
 
{
 
    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation"];
 
    animation.toValue=[NSValue valueWithCGPoint:point];
 
    animation.removedOnCompletion=NO;
 
    animation.fillMode=kCAFillModeForwards;
 
    return animation;
 
}
 
  
 
+(CABasicAnimation *)rotation:(float)dur degree:(float)degree direction:(int)direction repeatCount:(int)repeatCount //旋转
 
{
 
    CATransform3D rotationTransform  = CATransform3DMakeRotation(degree, 0, 0,direction);
 
    CABasicAnimation* animation;
 
    animation = [CABasicAnimation animationWithKeyPath:@"transform"];
 
  
 
animation.toValue= [NSValue valueWithCATransform3D:rotationTransform];
 
    animation.duration= dur;
 
animation.autoreverses= NO;
 
    animation.cumulative= YES;
 
    animation.removedOnCompletion=NO;
 
    animation.fillMode=kCAFillModeForwards;
 
    animation.repeatCount= repeatCount; 
 
animation.delegate= self;
 
  
 
return animation;
 
}
0 0
原创粉丝点击