iOS 之CABasicAnimation简单动画 组动画 顺序播放动画
2014-12-24 13:14
639 查看
//-(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 简单实现gif动画播放
- iOS 简单实现gif动画播放
- CABasicAnimation简单动画 组动画 顺序播放动画
- iOS 简单的播放gif动画
- iOS 简单的播放gif动画
- iOS几个功能:1.摇一摇;2.震动;3.简单的摇动动画;4.生成二维码图片;5.发送短信;6.播放网络音频等
- 动画的顺序播放
- 【iOS-Cocos2d游戏开发之十八】解决滚屏背景/拼接地图有黑边(缝隙)/动画播放出现毛边以及禁止游戏中自动锁屏问题!【2011年12月18日补充】
- ios中播放gif动画
- ios audioplayer播放声音失败是由于最简单的错误
- iOS 播放声音 最简单的方法
- IOS中通过Core Animation实现简单动画
- ios小案例:看图记字母(简单动画)
- iOS-实现简单的动画效果
- ios 简单的图片动画
- iOS 简单的动画连接
- android 简单图片动画播放实现
- 【iOS-Cocos2d游戏开发之十八】解决滚屏背景/拼接地图有黑边(缝隙)/动画播放出现毛边以及禁止游戏中自动锁屏问题!【2011年12月18日补充】
- iOS下UIButton压下后播放动画,松开后动画消失的实现
- 【iOS-Cocos2d游戏开发之十八】解决滚屏背景/拼接地图有黑边(缝隙)/动画播放出现毛边以及禁止游戏中自动锁屏问题!【2011年12月18日补充】