zoukankan      html  css  js  c++  java
  • iOS 转场动画 present

    在项目中没有创建 UINavgationController,无法使用默认的 push 方法 进行页面的跳转时。

    使用另一种页面跳转方法 :

      - (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion NS_AVAILABLE_IOS(5_0);

    常用的方法:

     //  结合控件的点击事件,例:常用的UIButton
     UIButton * button = [UIButton alloc] init];
     [button addTarget:self action:@selector(buttonClick) forControlEvents:(UIControlEventTouchUpInside)];
    
    //   默认跳转方式,从底部推出
    - (void)buttonClick {
         UIViewController * viewController = [UIViewController alloc] init];
         [self presentViewController: viewController animated:YES completion:nil];   
    }

    根据需求设置跳转时的样式:

    - (void)buttonClick {
          CATransition * animation = [CATransition animation];
    
          animation.duration = 0.5;    //  时间
    
          /**  type:动画类型
            *  pageCurl       向上翻一页
            *  pageUnCurl     向下翻一页
            *  rippleEffect   水滴
            *  suckEffect     收缩
            *  cube           方块
            *  oglFlip        上下翻转
            */
          animation.type = @"pageCurl";
    
           /**  type:页面转换类型
            *  kCATransitionFade       淡出
            *  kCATransitionMoveIn     覆盖
            *  kCATransitionReveal     底部显示
            *  kCATransitionPush       推出
            */
          animation.type = kCATransitionPush;
    
          //PS:type 更多效果请 搜索: CATransition
    
          /**  subtype:出现的方向
            *  kCATransitionFromRight       右
            *  kCATransitionFromLeft        左
            *  kCATransitionFromTop         上
            *  kCATransitionFromBottom      下
            */
          animation.subtype = kCATransitionFromRight;
    
          [self.view.window.layer addAnimation:animation forKey:nil];                   //  添加动作
          [self presentViewController: viewController animated:YES completion:nil];     //  跳转
      }
    
     //  PS:设置 type 属性时,两种写法

    在 UIViewController 中才可以调用 presentViewController 方法。
    但如果是监听 [自定义View] 中的一个 [UIButton事件] 进行跳转:

     //  自定义 View.h 文件中
     @property (nonatomic, strong) UIViewController      *   viewController;
    
    ---------------------
    
     //  自定义 View.m 文件中
     //  自定义View视图中的 UIButton
     self.button = [UIButton alloc] init];
     [self.button addTarget:self action:@selector(selfButtonClick:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //  self.button 点击方法
    - (void)selfButtonClick:(UIViewController *)otherVC {
       otherVC =  self.viewController;
    
      //  do soming
    
       [self presentViewController:otherVC animated:YES completion:nil];     //  跳转
    }
    
    -------------------
    
      //  绑定 自定义View 的 Controller 中
      self.自定义View.viewController = self;



    文/FFynn(简书作者)
    原文链接:http://www.jianshu.com/p/26a57835ef3c
    著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
  • 相关阅读:
    跟我一起学习ASP.NET 4.5 MVC4.0(二)(转)
    跟我一起学习ASP.NET 4.5 MVC4.0(一)(转)
    MVC3 Razor视图引擎的基础语法
    了解ASP.NET MVC几种ActionResult的本质:HttpStatusCodeResult & RedirectResult/RedirectToRouteResult
    通过一个模拟程序让你明白ASP.NET MVC是如何运行的
    ASP.NET中后台注册js脚本攻略(转)
    Python: 什么是*args和**kwargs
    配置mysql 及 设置密码
    java静态方法Static
    并发程序设计知识总结
  • 原文地址:https://www.cnblogs.com/zhangrunchao/p/6008529.html
Copyright © 2011-2022 走看看