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
  • 相关阅读:
    uni-app在小程序开发者工具:TypeError: Cannot read property ‘forceUpdate‘ of undefined
    windows部署多个tomcat并添加到服务开机自动启动
    区域填充算法和多边形填充的扫描线算法[转]
    如何在不规则多边形内均匀撒点的算法[转]
    基于Living Atlas数据为木里山体滑坡敏感性建模【转】
    重磅!前端开发技术之Vue架构知识分享[转]
    如何使用 IAM 策略授予对特定 AWS S3 文件夹的用户特定访问权限?
    XXL-JOB安装、配置、启动、停止教程
    centos7 部署YApi
    CentOS 7安装MySQL8.0
  • 原文地址:https://www.cnblogs.com/wuxiufang/p/3582784.html
Copyright © 2011-2022 走看看