#import "ViewController.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
{
NSArray *typeTitle;
NSArray *type;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.title = @"CATransition动画";
typeTitle = @[@"新视图将旧视图推出-kCATransitionPush",@"底部显示出来-kCATransitionReveal",@"kCATransitionMoveIn-移动覆盖原图",@"kCATransitionFade-交叉淡化过度",@"pageCurl-向上翻一页",@"pageUnCurl-向下翻一页",@"rippleEffect-滴水效果",@"suckEffect-收缩效果,如一块布被抽走",@"cube-立方体效果",@"oglFlip-上下翻转效果"];
type = @[@"kCATransitionPush",@"kCATransitionReveal",@"kCATransitionMoveIn",@"kCATransitionFade",@"pageCurl",@"pageUnCurl",@"rippleEffect",@"suckEffect",@"cube",@"oglFlip"];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return typeTitle.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *Indef = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Indef];
if (!cell) {
cell = [[UITableViewCell alloc] init];
}
cell.textLabel.text = typeTitle[indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"跳转到下个界面动画");
[self pushNextViewController:type[indexPath.row]];
}
//简单的
- (void)pushNextViewController:(NSString *)sender{
CATransition *transition = [CATransition animation];
//设置代理
/* When true, the animation is removed from the render tree once its
* active duration has passed. Defaults to YES. */
transition.delegate = self;
//动画的时间长短
transition.duration = 2.0f;
//动画进入方式
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
//动画类型
transition.type = sender;
//另一种设置动画的方法
// transition.type = @"pageCurl";
transition.subtype = kCATransitionFromBottom;
NextViewController *vc = [[NextViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
[self.navigationController.view.layer addAnimation:transition forKey:@"tran"];
/** timingFunction
*
* 用于变化起点和终点之间的插值计算,形象点说它决定了动画运行的节奏,比如是均匀变化(相同时间变化量相同)还是
* 先快后慢,先慢后快还是先慢再快再慢.
*
* 动画的开始与结束的快慢,有五个预置分别为(下同):
* kCAMediaTimingFunctionLinear 线性,即匀速
* kCAMediaTimingFunctionEaseIn 先慢后快
* kCAMediaTimingFunctionEaseOut 先快后慢
* kCAMediaTimingFunctionEaseInEaseOut 先慢后快再慢
* kCAMediaTimingFunctionDefault 实际效果是动画中间比较快.
*/
/*动画进入方式
kCATransitionFromRight;
kCATransitionFromLeft;
kCATransitionFromTop;//新界面从底部出来
kCATransitionFromBottom;//新界面从顶部出来
*/
/*动画类型
kCATransitionFade;//交叉淡化过度
kCATransitionMoveIn;//移动覆盖原图
kCATransitionPush;//新视图将旧视图推出
kCATransitionReveal;//底部显示出来
*/
/**
* 另一种设置方法
pageCurl //向上翻一页
pageUnCurl //向下翻一页
rippleEffect //滴水效果
suckEffect //收缩效果,如一块布被抽走
cube //立方体效果
oglFlip //上下翻转效果
*/
}
@end
iOS CATransition动画
猜你喜欢
转载自blog.csdn.net/JangJun521/article/details/46345641
今日推荐
周排行