CABasicAnimation简单动画 组动画 顺序播放动画
2013-08-28 16:00
309 查看
//-(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.delegate= self;
return animation;
}
- (CAAnimation *)animationRotate2
{
// rotate animation
CATransform3D rotationTransform = CATransform3DMakeRotation(M_PI, 1.0, 0, 0.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;//设置动画的方向,有四种,分别为kCATransitionFromRight、kCATransitionFromLeft、kCATransitionFromTop、kCATransitionFromBottom
//[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
-(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.delegate= self;
return animation;
}
- (CAAnimation *)animationRotate2
{
// rotate animation
CATransform3D rotationTransform = CATransform3DMakeRotation(M_PI, 1.0, 0, 0.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;//设置动画的方向,有四种,分别为kCATransitionFromRight、kCATransitionFromLeft、kCATransitionFromTop、kCATransitionFromBottom
//[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
相关文章推荐
- iOS 之CABasicAnimation简单动画 组动画 顺序播放动画
- iOS 简单的播放gif动画
- 动画的顺序播放
- CSS3两个动画顺序衔接播放
- 简单的动画播放
- Android:简单动画效果-淡入淡出播放
- iOS几个功能:1.摇一摇;2.震动;3.简单的摇动动画;4.生成二维码图片;5.发送短信;6.播放网络音频等
- 一个imageview播放动画,如此简单(包含imageview的所有属性,方法)
- android 简单图片动画播放的实例代码
- UIImageView-播放序列图(简单的动画效果实现)
- Android 简单动画播放
- iOS 简单实现gif动画播放
- MyMove,简单的 播放动画
- 简单的音乐播放,旋转动画
- iOS 简单的播放gif动画
- cocos2dx 几个精灵按照顺序播放动画解决方法
- cocos2dx 几个精灵依照顺序播放动画解决方法
- Core Animation 多个动画顺序播放
- CSS3两个动画顺序衔接播放
- iOS 简单实现gif动画播放