CABasicAnimation简单动画 组动画 顺序播放动画

//-(CABasicAnimation *)opacityTime:(float)time durTimes:(float)durTimes fromValue:(NSNumber *)fromvalue toValue:(NSNumber *)tovalue

-(CABasicAnimation *)opacityTimes_Animation:(float)repeatTimes durTimes:(float)time //有闪烁次数的动画 durTimes闪一次时间 repeatTimes次数

{

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

    animation.fromValue=[NSNumber numberWithFloat:1.0];

    animation.toValue=[NSNumber numberWithFloat:0.5];//透明度

    animation.repeatCount=FLT_MAX;

    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=[CABasicAnimationanimationWithKeyPath:@"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=[CABasicAnimationanimationWithKeyPath:@"transform.translation.y"];

    animation.toValue=y;

    animation.duration=time;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    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;

}

 

//缩放比例   orgin ---> scale 

-(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;

}

 


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

    //rotation旋转一次时间 repeatCount旋转次数  degree大概与方向有关   CATransform3DMakeRotation总是按最短路径来选择,当顺时针和逆时针的路径相同时,使用逆时针。若需要使其按顺时针旋转,用CAKeyframeAnimation 并在在顺时针路径上增加几个关键点即可。

    CATransform3D rotationTransform  = CATransform3DMakeRotation(degree, 0,0,direction);//(CGFloat angle, CGFloat x,CGFloat y, CGFloat z)坐标控制旋转方式。

    CABasicAnimation* animation;

    animation = [CABasicAnimation animationWithKeyPath:@"transform"];

    

    animation.toValue= [NSValue valueWithCATransform3D:rotationTransform];

    animation.duration= dur;

    animation.autoreverses= NO;//为真时,旋转一次,再按原方向转回去

    animation.cumulative= YES;//NO时,旋转一次,回到原图再旋转

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    animation.repeatCount= repeatCount;

    animation.delegateself;

    

    return animation;

}

- (CAAnimation *)animationRotate2

{

// rotate animation

CATransform3D rotationTransform  = CATransform3DMakeRotation(M_PI1.000.0);


    CABasicAnimation* animation;

    animation = [CABasicAnimation animationWithKeyPath:@"transform"];


animation.toValue = [NSValue valueWithCATransform3D:rotationTransform];

    animation.duration = 0.5;

animation.autoreverses = NO;

    animation.cumulative = YES;

    animation.repeatCount = FLT_MAX //"forever":FLT_MAX

//设置开始时间,能够连续播放多组动画

animation.beginTime = 0.5;

//设置动画代理

animation.delegate = self;


return animation;

}

 

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

{

    CAAnimationGroup *animation=[CAAnimationGroup animation];

    animation.animations=animationAry;

    animation.duration=time;

    animation.delegate=self;

    animation.repeatCount=repeatTimes;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    return animation;

}

 

- (CAAnimation *)animationRotate1{

    

    CATransition *animation = [CATransition animation];

    

    animation.duration = 4.0f;

    

    animation.timingFunction = UIViewAnimationCurveEaseInOut;

    

    animation.type = kCATransitionMoveIn;//设置4种动画效果 kCATransitionFade淡出kCATransitionMoveIn覆盖原图 kCATransitionPush推出 kCATransitionReveal底部显出来

    

    //animation.subtype = kCATransitionFromRight;//设置动画的方向,有四种,分别为kCATransitionFromRightkCATransitionFromLeftkCATransitionFromTopkCATransitionFromBottom

    

    //[animation setType:@"pageCurl"];//pageCurl 向上翻一页, pageUnCurl 向下翻一页, rippleEffect滴水效果 ,suckEffect 收缩效果,如一块布被抽走 ,  cube 立方体效果 ,  oglFlip 上下翻转效果,suckEffect

    

    

    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;

}


按顺序运行 动画块

1.设置委托的第一个动画
[ UIView  setAnimationDidStopSelector : @selector ( animationDidStop : finished :)];
http://d2100.com/questions/12251

2.还可以用动画组来实现先后,(动画组里的动画不设置时间的话,是同时执行的)

设置时间可以有先后效果 可以看看这里


http://blog.sina.com.cn/s/blog_7f6480790101awa2.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值