改变UIViewController的push方式

UIViewController的push默认的是从右往左压入栈,但是有时我们需要其他的方式例如,是从左往右压入栈。还有其他各种方式,如下
方法一:是通过给导航栏下要压入栈的控制器对应的view的layer添加动画

- (IBAction)toPersonalCenterViewControllerAction:(id)sender {
    UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    PersonalCenterViewController *vc = [board instantiateViewControllerWithIdentifier:@"PersonalCenterViewController"];

    CATransition *transition = [CATransition animation];
    transition.duration = .5f;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    transition.type = kCATransitionPush;push方法
    transition.subtype = kCATransitionFromLeft;从左到右
    transition.delegate = self;
    [self.controller.navigationController.view.layer addAnimation:transition forKey:nil];

    [self.controller.navigationController pushViewController:vc animated:YES];
}
 对应的动画效果,还有对应的动画方向如下
transition.type 

/* Common transition types. */

CA_EXTERN NSString * const kCATransitionFade
    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCATransitionMoveIn
    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCATransitionPush
    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCATransitionReveal
    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);

 
transition.subtype
/* Common transition subtypes. */

CA_EXTERN NSString * const kCATransitionFromRight
    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCATransitionFromLeft
    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCATransitionFromTop
    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCATransitionFromBottom
    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
 
方法二:通过自定义navigationController
#import <UIKit/UIKit.h>
@interface CustomViewController : UINavigationController
@end
 
@implementation CustomViewController
 
-(UIViewController * )popViewControllerAnimated:(BOOL)animated
{
    if (animated) {
        [UIViewbeginAnimations:@"1"context:nil];
        [UIViewsetAnimationCurve:UIViewAnimationCurveLinear];
        [UIViewsetAnimationDuration:1];
        [UIViewsetAnimationTransition:UIViewAnimationTransitionFlipFromRightforView:self.viewcache:NO];
        [UIViewcommitAnimations];
       
    }
    return [superpopViewControllerAnimated:animated];
}
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (animated) {
        [UIViewbeginAnimations:@"2"context:nil];
        [UIViewsetAnimationCurve:UIViewAnimationCurveLinear];
        [UIViewsetAnimationDuration:2];
        [UIViewsetAnimationTransition:UIViewAnimationTransitionCurlDownforView:self.viewcache:NO];
        [UIViewcommitAnimations];
    }
         [super pushViewController:viewController animated:animated];
}
@end

 

转载于:https://www.cnblogs.com/wuxiufang/p/3582784.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值