改变navigationController 跳转动画

在iOS 项目中页面跳转是特别常见的事情。但要使用pushViewController跳转动画是由系统决定的。但有时需要修改系统跳转动画就比较麻烦了,需要重写navigationController 的 pushViewController 动画。不多说直接上代码吧。

在代码之前是需要引入QuartzCore库

#import <QuartzCore/QuartzCore.h>

在要跳转的方法里面写

pushViewController 
{
    CATransition *animation = [CATransition animation];
    
    [animation setDuration:0.5];
    
    [animation setType: kCATransitionMoveIn];
    
    [animation setSubtype: kCATransitionFromBottom];
    
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
    

    YKProductSizeDetailViewController *sizeDetail=[[YKProductSizeDetailViewControlleralloc] initWithNibName:@"YKProductSizeSelectController"bundle:nil];

    //sizeDetail.delegate=self;

    sizeDetail.tag=fromTag;

    sizeDetail.product=product;

    sizeDetail.inpusPage=99;

    sizeDetail.needTipToSelectSize=(fromTag!=YK_TAG_SIZE_SELECT_FROM_SIZE_DETAIL ?YES:NO);

    [sizeDetail setSizeList:[productdetailSizeList]];

    [[selfnavigationController] pushViewController:sizeDetail animated:NO];

  [self.navigationController.view.layer addAnimation:animation forKey:nil];

}

 

返回

popViewControllerAnimated

{

    CATransition *animation = [CATransitionanimation];

    [animation setDuration:0.5];

    [animation setType: kCATransitionMoveIn];

    [animation setSubtype: kCATransitionFromTop];

    [animation setTimingFunction:[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionDefault]];

    [self.navigationController.view.layeraddAnimation:animation forKey:nil];

    [[selfnavigationController] popViewControllerAnimated:NO];

}

 

 

 

 

 

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注