• 改变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
  • 相关阅读:
    20201029模拟赛总结
    20201023模拟赛总结
    贪心题目选讲
    博客阅览帮助
    NTT&FFT(快速?变换,以及扩展)
    数论知识小结 [基础篇]
    数论知识小结 [微提高篇]
    零化多项式/特征多项式/最小多项式/常系数线性齐次递推
    牛顿迭代快速求解定义域为多项式的函数零点
    求导/泰勒展开
  • 原文地址:https://www.cnblogs.com/wuxiufang/p/3582784.html
Copyright © 2020-2023  润新知