zoukankan      html  css  js  c++  java
  • 改变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
  • 相关阅读:
    编写测试用例的七种方法
    字节输出流OutputStream,字节输入流InputStream。。。字符输入流Reader, 字符输出流Writer
    项目分层(分包)
    File,,, 文件和文件夹的创建删除,,, listFiles()方法介绍,,,文件过滤器,,, 递归
    登录,注册
    分层分包增删改查
    预处理对象,增删改查
    异常
    斗地主,,,Java中final、finalize()、finally三者的区别
    静态导入,,,可变参数,,, Collections集合工具类
  • 原文地址:https://www.cnblogs.com/wuxiufang/p/3582784.html
Copyright © 2011-2022 走看看