IOS动画

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

////ViewController.m//IOS-动画特效////Created by wangtouwang on 15/5/5.//Copyright (c) 2015年 wangtouwang. All rights reserved.//#import"ViewController.h"#definekDuration 0.7//动画持续时间(秒)#defineKS_HEIGTH [UIScreen mainScreen].bounds.size.height#defineKS_WIDTH [UIScreen mainScreen].bounds.size.Width@interfaceViewController ()

@PRoperty(nonatomic,strong) UIView*imageView;@end@implementationViewController@synthesizetypeID;@synthesizeblueView;@synthesizegreenView;-(void)animationFunction:(UIButton *)btn{

NSInteger index=btn.tag;

CATransition*transition =[CATransition animation];//代理transition.delegate=self;//持续时间transition.duration=kDuration;//类型transition.type =[self getAnimationType:index];//方向transition.subtype =[self getSubType];//动画的开始与结束的快慢*/transition.timingFunction =UIViewAnimationCurveEaseInOut;//事件源NSInteger blue =[[_imageView subviews] indexOfObject:blueView];

NSInteger green=[[_imageView subviews] indexOfObject:greenView];

[_imageView exchangeSubviewAtIndex:green withSubviewAtIndex:blue];//开始动画[_imageView.layer addAnimation:transition forKey:@"animation"];

}-(void)animationFunction2:(UIButton *)btn{

NSInteger index=btn.tag;

CGContextRef context=UIGraphicsGetCurrentContext();

[UIView beginAnimations:nil context:context];//开始一个动画块[UIView setAnimationDelegate:self];//代理[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//设置动画块中的动画属性变化的曲线。[UIView setAnimationDuration:kDuration];//在动画块中设置动画的延迟属性 (以秒为单位)//在动画块中为视图设置过渡switch(index) {case10:

[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];

break;case9:

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];

break;case12:

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];

break;case11:

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];

break;default:

break;

}//事件源NSInteger blue =[[_imageView subviews] indexOfObject:blueView];

NSInteger green=[[_imageView subviews] indexOfObject:greenView];

[_imageView exchangeSubviewAtIndex:green withSubviewAtIndex:blue];//动画完毕后调用某个方法//[UIView setAnimationDidStopSelector:@selector(animationFinished:)];[UIView commitAnimations];//结束一个动画块并开始当他在动画块外时}-(NSString *)getAnimationType:(NSInteger)index{

NSString*type=nil;switch(index) {case5:

type=kCATransitionFade;

break;case6:

type=kCATransitionPush;

break;case7:

type=kCATransitionReveal;

break;case8:

type=kCATransitionMoveIn;

break;case4:

type=@"cube";

break;case3:

type=@"suckEffect";

break;case1:

type=@"pageCurl";

break;case2:

type=@"pageUnCurl";

break;default:

break;

}returntype;

}-(NSString *)getSubType{

NSString*subtype =nil;switch(self.typeID) {case0:

subtype=kCATransitionFromLeft;

break;case1:

subtype=kCATransitionFromBottom;

break;case2:

subtype=kCATransitionFromRight;

break;case3:

subtype=kCATransitionFromTop;

break;default:

break;

}

self.typeID+=1;if(self.typeID >3) {

self.typeID=0;

}returnsubtype;

}- (void)viewDidLoad {

[super viewDidLoad];

[self.view setBackgroundColor:[UIColor whiteColor]];

[self.navigationItem setTitle:@"动画特效"];

UIButton*addBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(10,70,80,30)];

[addBtn1 setTitle:@"翻页"forState:UIControlStateNormal];

addBtn1.titleLabel.font=[UIFont systemFontOfSize:13.0f];

[addBtn1 setBackgroundColor:[UIColor grayColor]];

addBtn1.tag=1;

[addBtn1 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:addBtn1];

UIButton*addBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(100,70,80,30)];

[addBtn2 setTitle:@"反翻页"forState:UIControlStateNormal];

addBtn2.titleLabel.font=[UIFont systemFontOfSize:13.0f];

[addBtn2 setBackgroundColor:[UIColor grayColor]];

addBtn2.tag=2;

[addBtn2 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:addBtn2];

UIButton*addBtn3 = [[UIButton alloc] initWithFrame:CGRectMake(190,70,80,30)];

[addBtn3 setTitle:@"波纹"forState:UIControlStateNormal];

addBtn3.titleLabel.font=[UIFont systemFontOfSize:13.0f];

[addBtn3 setBackgroundColor:[UIColor grayColor]];

addBtn3.tag=3;

[addBtn3 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:addBtn3];

UIButton*addBtn4 = [[UIButton alloc] initWithFrame:CGRectMake(280,70,80,30)];

[addBtn4 setTitle:@"立方体"forState:UIControlStateNormal];

addBtn4.titleLabel.font=[UIFont systemFontOfSize:13.0f];

[addBtn4 setBackgroundColor:[UIColor grayColor]];

addBtn4.tag=4;

[addBtn4 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:addBtn4];

UIButton*addBtn5 = [[UIButton alloc] initWithFrame:CGRectMake(10,110,80,30)];

[addBtn5 setTitle:@"淡化"forState:UIControlStateNormal];

addBtn5.titleLabel.font=[UIFont systemFontOfSize:13.0f];

[addBtn5 setBackgroundColor:[UIColor grayColor]];

addBtn5.tag=5;

[addBtn5 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:addBtn5];

UIButton*addBtn6 = [[UIButton alloc] initWithFrame:CGRectMake(100,110,80,30)];

[addBtn6 setTitle:@"推挤"forState:UIControlStateNormal];

addBtn6.titleLabel.font=[UIFont systemFontOfSize:13.0f];

[addBtn6 setBackgroundColor:[UIColor grayColor]];

addBtn6.tag=6;

[addBtn6 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:addBtn6];

UIButton*addBtn7 = [[UIButton alloc] initWithFrame:CGRectMake(190,110,80,30)];

[addBtn7 setTitle:@"揭开"forState:UIControlStateNormal];

addBtn7.titleLabel.font=[UIFont systemFontOfSize:13.0f];

[addBtn7 setBackgroundColor:[UIColor grayColor]];

addBtn7.tag=7;

[addBtn7 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:addBtn7];

UIButton*addBtn8 = [[UIButton alloc] initWithFrame:CGRectMake(280,110,80,30)];

[addBtn8 setTitle:@"覆盖"forState:UIControlStateNormal];

addBtn8.titleLabel.font=[UIFont systemFontOfSize:13.0f];

[addBtn8 setBackgroundColor:[UIColor grayColor]];

addBtn8.tag=8;

[addBtn8 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:addBtn8];

UIButton*addBtn9 = [[UIButton alloc] initWithFrame:CGRectMake(10,150,80,30)];

[addBtn9 setTitle:@"上翻"forState:UIControlStateNormal];

addBtn9.titleLabel.font=[UIFont systemFontOfSize:13.0f];

[addBtn9 setBackgroundColor:[UIColor grayColor]];

addBtn9.tag=9;

[addBtn9 addTarget:self action:@selector(animationFunction2:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:addBtn9];

UIButton*addBtn10 = [[UIButton alloc] initWithFrame:CGRectMake(100,150,80,30)];

[addBtn10 setTitle:@"下翻"forState:UIControlStateNormal];

addBtn10.titleLabel.font=[UIFont systemFontOfSize:13.0f];

[addBtn10 setBackgroundColor:[UIColor grayColor]];

addBtn10.tag=10;

[addBtn10 addTarget:self action:@selector(animationFunction2:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:addBtn10];

UIButton*addBtn11 = [[UIButton alloc] initWithFrame:CGRectMake(190,150,80,30)];

[addBtn11 setTitle:@"左翻"forState:UIControlStateNormal];

addBtn11.titleLabel.font=[UIFont systemFontOfSize:13.0f];

[addBtn11 setBackgroundColor:[UIColor grayColor]];

addBtn11.tag=11;

[addBtn11 addTarget:self action:@selector(animationFunction2:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:addBtn11];

UIButton*addBtn12 = [[UIButton alloc] initWithFrame:CGRectMake(280,150,80,30)];

[addBtn12 setTitle:@"右翻"forState:UIControlStateNormal];

addBtn12.titleLabel.font=[UIFont systemFontOfSize:13.0f];

[addBtn12 setBackgroundColor:[UIColor grayColor]];

addBtn12.tag=12;

[addBtn12 addTarget:self action:@selector(animationFunction2:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:addBtn12];

_imageView= [[UIView alloc] initWithFrame:CGRectMake(0,190, [UIScreen mainScreen].bounds.size.width, KS_HEIGTH-190)];

[self.view addSubview:_imageView];

blueView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"XXX_123.png"]];

blueView.frame=CGRectMake(0,0, [UIScreen mainScreen].bounds.size.width, KS_HEIGTH-150);

[_imageView addSubview:blueView];

greenView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"XXX_321.png"]];

greenView.frame=CGRectMake(0,0, [UIScreen mainScreen].bounds.size.width, KS_HEIGTH-150);

[_imageView addSubview:greenView];

}- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

}@end

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航