//翻页效果动画 左边
[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:YES];
[UIView commitAnimations];
//翻页效果动画 右边
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:0.35f];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
//lar动画,从上到下模糊
CATransition *animation = [CATransition animation];
[animation setDuration:2.0f];
[animation setFillMode:kCAFillModeForwards];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromBottom];
[self.view.layer addAnimation:animation forKey:nil];
//折页效果动画
[UIView animateWithDuration:0.35f animations:^
{
self.view.transform = CGAffineTransformMakeScale(0.001, 0.001);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
// 向右旋转45°缩小到最小,然后再从小到大推出.
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.70, 0.40, 0.80)];
/**
* 其他效果:
* 从底部向上收缩一半后弹出
* animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.0, 1.0, 0.0)];
*
* 从底部向上完全收缩后弹出
* animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 1.0, 0.0, 0.0)];
*
* 左旋转45°缩小到最小,然后再从小到大推出.
* animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.50, -0.50, 0.50)];
*
* 旋转180°缩小到最小,然后再从小到大推出.
* animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.1, 0.2, 0.2)];
*/
animation.duration = 2;
animation.repeatCount = 1;
[self.view.layer addAnimation:animation forKey:nil];
}
completion:^(BOOL finished)
{
[UIView animateWithDuration:0.35f animations:^
{
self.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
}];
}];
//从下到上模糊推出
CATransition *animation = [CATransition animation];
[animation setDuration:1.0f];
[animation setType:kCATransitionReveal];
[animation setSubtype:kCATransitionFromTop];
[animation setFillMode:kCAFillModeForwards];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[self.view.layer addAnimation:animation forKey:nil];
//旋转动画
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat:(2 * M_PI) * 2];
rotationAnimation.duration = 0.35f;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.toValue = [NSNumber numberWithFloat:0.0];
scaleAnimation.duration = 0.35f;
scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.duration = 2.35f;
animationGroup.autoreverses = YES;
animationGroup.repeatCount = 1;
animationGroup.animations =[NSArray arrayWithObjects:rotationAnimation, nil];
[self.view.layer addAnimation:animationGroup forKey:@"animationGroup"];
//动画->contents
CABasicAnimation * b=[CABasicAnimation animationWithKeyPath:@"contents"];
b.duration=3;
b.fromValue=(__bridge id)([UIImage imageNamed:@"3"].CGImage);
b.toValue=(__bridge id)([UIImage imageNamed:@"2"].CGImage);
b.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
b.repeatCount=CGFLOAT_MAX;
b.autoreverses=YES;
[self.layer addAnimation:b forKey:nil];
//shadowColor阴影颜色
[self.layer setShadowColor:[UIColor redColor].CGColor];
//shadowOffset阴影偏移
[self.layer setShadowOffset:CGSizeMake(2, 2)];
//阴影透明度
[self.layer setShadowOpacity:0.5];
//阴影半径
self.layer.shadowRadius = 2;
//动画->transform.scale
CABasicAnimation * pulse = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
pulse.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
pulse.duration = 1;
pulse.repeatCount = CGFLOAT_MAX;
pulse.autoreverses = YES;
pulse.fromValue = [NSNumber numberWithFloat:.8];
pulse.toValue = [NSNumber numberWithFloat:1.2];
pulse.fillMode=kCAFillModeForwards;
pulse.removedOnCompletion=NO;
[self.layer addAnimation:pulse forKey:nil];
//动画->cornerRadius
CABasicAnimation * b=[CABasicAnimation animationWithKeyPath:@"cornerRadius"];
b.duration=1;
b.fromValue=[NSNumber numberWithInt:0];
b.toValue=[NSNumber numberWithInt:20];
b.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
b.repeatCount=CGFLOAT_MAX;
b.fillMode=kCAFillModeForwards;
b.removedOnCompletion=NO;
b.autoreverses=YES;
[self.layer addAnimation:b forKey:nil];
//永久闪烁的动画
+(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;
}
来源:https://www.cnblogs.com/tongyuling/p/4665151.html