您的位置:首页 > 运维架构

NavigationController 自定义pop和push动画

2016-07-19 18:24 225 查看

有时候我们需要自定义navigationController push和pop界面切换动画,用到的代码如下:

For Push 一、利用UIView :

kkkViewController *VC = [[kkkViewController alloc] init];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:1];
[self.navigationController pushViewController:VC animated:YES];

// 几种动画的样式(枚举值)
UIViewAnimationTransitionNone,
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,

[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
[UIView commitAnimations];


For Push 二、利用CATransition实现动画 :

CATransition *transition = [CATransition animation];
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = @"cube";
transition.subtype = kCATransitionFromRight;  // 这里可以选择四种
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];

kkkViewController *VC = [[kkkViewController alloc] init];
[self.navigationController pushViewController:VC animated:YES];


其中的动画类型有:

transition.type = kCATransitionFade;

transition.type = kCATransitionPush;

transition.type = kCATransitionReveal;

transition.type = kCATransitionMoveIn;

transition.type = @"cube";

transition.type = @"suckEffect";

// 页面旋转
transition.type = @"oglFlip";

//水波纹
transition.type = @"rippleEffect";

transition.type = @"pageCurl";

transition.type = @"pageUnCurl";

transition.type = @"cameraIrisHollowOpen";

transition.type = @"cameraIrisHollowClose";


For Pop 一、利用UIView :

[UIView  beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.375];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];


For Pop 二、利用CATransition :

CATransition* transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
//transition.subtype = kCATransitionFromTop; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[[self navigationController] popViewControllerAnimated:NO];


具体的动画参数请自行更改。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  pop 动画 界面 push