CABasicAnimation 几个常用的动画效果

转载 2015年07月07日 18:28:15

来自:http://blog.sina.com.cn/s/blog_8a6c97b501010lcf.html
其他参考:http://tergol.blog.163.com/blog/static/1706950282010112811257949/


+(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;
}
 
实现view放大再缩小的效果
 
- (void)viewDidLoad {      [super viewDidLoad];  layer=[CALayer layer];  layer.frame=CGRectMake(50, 200, 50, 50);  layer.backgroundColor=[UIColor orangeColor].CGColor;  layer.cornerRadius=8.0f;  CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];  animation.duration=4.0f;  animation.autoreverses=NO;  animation.repeatCount=1;  animation.toValue=[NSNumber numberWithInt:-10];  animation.fromValue=[NSNumber numberWithInt:200];  animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];  CABasicAnimation *animationZoomIn=[CABasicAnimation animationWithKeyPath:@"transform.scale"];  animationZoomIn.duration=2.0f;  animationZoomIn.autoreverses=NO;  animationZoomIn.repeatCount=1;  animationZoomIn.toValue=[NSNumber numberWithFloat:1.56];  animationZoomIn.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];  CABasicAnimation *animationZoomOut=[CABasicAnimation animationWithKeyPath:@"transform.scale"];  animationZoomOut.beginTime=2.0f;  animationZoomOut.duration=2.0f;  animationZoomOut.autoreverses=NO;  animationZoomOut.repeatCount=1;  animationZoomOut.toValue=[NSNumber numberWithFloat:.01];  animationZoomOut.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];  CAAnimationGroup *group=[CAAnimationGroup animation];  group.duration=4.0f;  group.animations=[NSArray arrayWithObjects: animation, animationZoomIn, animationZoomOut,nil];  group.removedOnCompletion=NO;  group.fillMode=kCAFillModeForwards;  [layer addAnimation:group forKey:nil];  [self.view.layer addSublayer:layer];  //layer.hidden=YES;  } 

CABasicAnimation 几个常用的动画效果

+(CABasicAnimation *)opacityForever_Animation:(float)time //永久闪烁的动画 {     CABasicAnimation *...
  • u011545929
  • u011545929
  • 2014年08月21日 14:25
  • 774

几个常用的动画效果

+(CABasicAnimation *)opacityForever_Animation:(float)time //永久闪烁的动画 {     CABasicAnimation *...
  • langyuejing
  • langyuejing
  • 2014年07月30日 13:49
  • 518

CABasicAnimation 动画效果

CABasicAnimation 自己只有三个property   fromValue  toValue  ByValue 当你创建一个 CABasicAnimation 时,你需要...
  • zwp438123895
  • zwp438123895
  • 2014年05月29日 21:46
  • 343

iOS - CABasicAnimation使用总结

原文链接:http://www.jianshu.com/p/02c341c748f9# 实例化 使用方法animationWithKeyPath:对 CABasicAnimation进行实例化,...
  • yuqingzhude
  • yuqingzhude
  • 2016年09月26日 16:46
  • 2762

使用CABasicAnimation实现的动画效果(一)

这个动画采用了CABasicAnimation和CAAnimationGroup来实现的,改变位置、改变大小、按钮圆角数合在一起形成一个组合动画。 原来是准备在CABasicAnimation中通过...
  • zm_dlf
  • zm_dlf
  • 2016年03月16日 11:44
  • 803

CABasicAnimation用法详解

CABasicAnimation 自己只有三个property   fromValue  toValue  ByValue 当你创建一个 CABasicAnimation 时,你...
  • daiyelang
  • daiyelang
  • 2013年11月29日 15:41
  • 5145

iOSCABasicAnimation的创建、停止和恢复

#pragma mark - 当前视图被触摸 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {      ...
  • xinxisxx
  • xinxisxx
  • 2015年05月13日 15:48
  • 3903

CABasicAnimation 热门动画效果

几个可以用来实现热门APP应用PATH中menu效果的几个方法 +(CABasicAnimation *)opacityForever_Animation:(float)time//永久闪烁的动...
  • humingtao2013
  • humingtao2013
  • 2014年04月29日 19:03
  • 1235

CABasicAnimation的使用方法(移动,旋转,缩放)

设定动画CABasicAnimation的属性和说明 属性 说明 duration 动画的时间 repeatCount 重复的次数。不停重复设置为 HUGE_VALF rep...
  • chenyongkai1
  • chenyongkai1
  • 2017年07月18日 18:33
  • 880

iOS动画详解 (CABasicAnimation,UIBezierPath,CAShapeLayer)

动效设计一直是iOS平台的优势,良好的动效设计可以很好地提升用户体验。而动画则是动效的基础支撑。本动画将从易到难逐步分析,从CABasicAnimation,UIBezierPath,CAShapeL...
  • sharpyl
  • sharpyl
  • 2017年01月06日 16:06
  • 1400
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:CABasicAnimation 几个常用的动画效果
举报原因:
原因补充:

(最多只允许输入30个字)