NavigationController 自定义pop和push动画

有时候我们需要自定义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]; 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值