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];
具体的动画参数请自行更改。
相关文章推荐
- Gifski:一个跨平台的高质量 GIF 编码器
- 模仿动画的放大缩小容器
- jQuery 1.9.1源码分析系列(十五)动画处理之缓动动画核心Tween
- Android实现定制返回按钮动画效果的方法
- Android中ViewFlipper的使用及设置动画效果实例详解
- jQuery实现美观的多级动画效果菜单代码
- winform异型不规则界面设计的实现方法
- php判断GIF图片是否为动画的方法
- 在ASP.NET 2.0中操作数据之二十:定制数据修改界面
- jQuery实现动画效果circle实例
- javaScript中push函数用法实例分析
- HTML5游戏引擎LTweenLite实现的超帅动画效果(附demo源码下载)
- 浅析JavaScript动画
- js排序动画模拟-插入排序
- javascript+HTML5的Canvas实现Lab单车动画效果
- 基于javascript实现漂亮的页面过渡动画效果附源码下载
- js实现按钮颜色渐变动画效果
- 超赞的jQuery图片滑块动画特效代码汇总
- jQuery实现连续动画效果实例分析
- 利用jquery制作滚动到指定位置触发动画