自定义NavigationController 的Push 和 Pop过渡动画
2015-10-30 15:43
330 查看
现在开发ios项目有两种或者可以说三种方式:
(1)纯代码
纯代码加Xib
(2)storyboard
so,自定义过渡动画的方式也有两种,但是动画的实现都是一样的。
先说一下过渡动画的实现方式:一共有三种说白了都是控制View的CATransition动画。
第一种:
代码如下:
NKYellowViewController *dst = [[NKYellowViewController
alloc]init];
[UIView
transitionWithView:self.navigationController.view
duration:1
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.navigationController
pushViewController:dst
animated:NO];
}
completion:nil];
注意:第一个参数为self.navigationController.view
第二种:
代码如下:
[UIView
transitionFromView:self.view
toView:dst.view
duration:1
options:UIViewAnimationOptionTransitionFlipFromTop
completion:^(BOOL finished) {
[self.navigationController
pushViewController:dst animated:NO];
}];
注意:第一个参数为self.view
第三种:
代码如下:
CATransition *transition = [CATransition
animation];
transition.duration =
1.0f;
transition.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseIn];
transition.type =
kCATransitionMoveIn;
transition.subtype =
kCATransitionFromTop;
[self.navigationController.view.layer
addAnimation:transition
forKey:nil];
[self.navigationController
pushViewController:dst animated:YES];
动画的类型有一下几种,效果自行尝试
/*
animation.type = kCATransitionFade;
animation.type = kCATransitionPush;
animation.type = kCATransitionReveal;
animation.type = kCATransitionMoveIn;
animation.type = @"cube";
animation.type = @"suckEffect";
// 页面旋转
animation.type = @"oglFlip";
//水波纹
animation.type = @"rippleEffect";
animation.type = @"pageCurl";
animation.type = @"pageUnCurl";
animation.type = @"cameraIrisHollowOpen";
animation.type = @"cameraIrisHollowClose";
*/
接下来说一下纯代码和storyboard的分别实现
(1)纯代码
如果用代码实现的话,大部分都是写在事件处理的函数里,如一下代码下载button的事件处理函数里
push:
- (void)pushViewController:(UIButton *)button
{
NKYellowViewController *dst = [[NKYellowViewController
alloc]init];
[UIView
transitionWithView:self.navigationController.view
duration:1
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.navigationController
pushViewController:dst
animated:NO];
}
completion:nil];
}
pop:
- (void)back {
[UIView
transitionWithView:self.navigationController.view
duration:1
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.navigationController
popViewControllerAnimated:NO];
}
completion:nil];
}
***动画代码可以任意替换,push和pop不对应也可以。
(2)storyboard
界面设计如下:
具体实现:
自定义segue,继承于UIStoryBoardSegue并重写perform方法。
<1>继承关系
@interface NKSegue :
UIStoryboardSegue
<2>重写方法
- (void)perform
{
UIViewController *src =
self.sourceViewController;
UIViewController *dst =
self.destinationViewController;
[UIView
transitionWithView:src.navigationController.view
duration:1
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[src.navigationController
pushViewController:dst
animated:NO];
}
completion:nil];
}
<3>设置segue,在右侧面板的属性检查器中segue Class设置为自定义的Segue类
返回同样是在返回函数里实现动画代码就ok了。
(1)纯代码
纯代码加Xib
(2)storyboard
so,自定义过渡动画的方式也有两种,但是动画的实现都是一样的。
先说一下过渡动画的实现方式:一共有三种说白了都是控制View的CATransition动画。
第一种:
代码如下:
NKYellowViewController *dst = [[NKYellowViewController
alloc]init];
[UIView
transitionWithView:self.navigationController.view
duration:1
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.navigationController
pushViewController:dst
animated:NO];
}
completion:nil];
注意:第一个参数为self.navigationController.view
第二种:
代码如下:
[UIView
transitionFromView:self.view
toView:dst.view
duration:1
options:UIViewAnimationOptionTransitionFlipFromTop
completion:^(BOOL finished) {
[self.navigationController
pushViewController:dst animated:NO];
}];
注意:第一个参数为self.view
第三种:
代码如下:
CATransition *transition = [CATransition
animation];
transition.duration =
1.0f;
transition.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseIn];
transition.type =
kCATransitionMoveIn;
transition.subtype =
kCATransitionFromTop;
[self.navigationController.view.layer
addAnimation:transition
forKey:nil];
[self.navigationController
pushViewController:dst animated:YES];
动画的类型有一下几种,效果自行尝试
/*
animation.type = kCATransitionFade;
animation.type = kCATransitionPush;
animation.type = kCATransitionReveal;
animation.type = kCATransitionMoveIn;
animation.type = @"cube";
animation.type = @"suckEffect";
// 页面旋转
animation.type = @"oglFlip";
//水波纹
animation.type = @"rippleEffect";
animation.type = @"pageCurl";
animation.type = @"pageUnCurl";
animation.type = @"cameraIrisHollowOpen";
animation.type = @"cameraIrisHollowClose";
*/
接下来说一下纯代码和storyboard的分别实现
(1)纯代码
如果用代码实现的话,大部分都是写在事件处理的函数里,如一下代码下载button的事件处理函数里
push:
- (void)pushViewController:(UIButton *)button
{
NKYellowViewController *dst = [[NKYellowViewController
alloc]init];
[UIView
transitionWithView:self.navigationController.view
duration:1
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.navigationController
pushViewController:dst
animated:NO];
}
completion:nil];
}
pop:
- (void)back {
[UIView
transitionWithView:self.navigationController.view
duration:1
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.navigationController
popViewControllerAnimated:NO];
}
completion:nil];
}
***动画代码可以任意替换,push和pop不对应也可以。
(2)storyboard
界面设计如下:
具体实现:
自定义segue,继承于UIStoryBoardSegue并重写perform方法。
<1>继承关系
@interface NKSegue :
UIStoryboardSegue
<2>重写方法
- (void)perform
{
UIViewController *src =
self.sourceViewController;
UIViewController *dst =
self.destinationViewController;
[UIView
transitionWithView:src.navigationController.view
duration:1
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[src.navigationController
pushViewController:dst
animated:NO];
}
completion:nil];
}
<3>设置segue,在右侧面板的属性检查器中segue Class设置为自定义的Segue类
返回同样是在返回函数里实现动画代码就ok了。
相关文章推荐
- Linux:alias永久生效
- Hadoop五大守护进程的三种启动与关闭方式
- Linux:alias永久生效
- Linux下从svn导出项目
- j2ee在tomcat服务器下跟一个不同的名字
- nginx负载均衡配置
- 查看Linux版本号
- linux shell小功能备忘
- Linux下安装jdk
- linux硬链接与软链接
- Linux下各路径的作用
- Linux下安装mysql
- 协同推荐SlopeOne 算法
- Codeforces 590D Top Secret Task
- java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory错误
- linux 空间不够,磁盘挂载
- onCreate、onStart、onResume、onPause、onStop、onDestory(转)
- 谷歌警告部分网站:别拿不相关搜索结果骗人
- tomcat长连接、短连接配置及用途
- 修改tomcat默认使用的jdk版本