您的位置:首页 > 移动开发 > IOS开发

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: