• 【代码笔记】iOS-Transition动画


    一,工程图。

    二,代码。

    RootViewController.h

    #import <UIKit/UIKit.h>
    
    @interface RootViewController : UIViewController
    
    @end

     

    RootViewController.m

    复制代码
    #import "RootViewController.h"
    #import "FirstViewController.h"
    
    @interface RootViewController ()
    
    @end
    
    @implementation RootViewController
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        
        
        self.title=@"首页";
        self.view.backgroundColor=[UIColor redColor];
        
        
        /* 过渡效果
         fade     //交叉淡化过渡(不支持过渡方向)
         push     //新视图把旧视图推出去
         moveIn   //新视图移到旧视图上面
         reveal   //将旧视图移开,显示下面的新视图
         cube     //立方体翻滚效果
         oglFlip  //上下左右翻转效果
         suckEffect   //收缩效果,如一块布被抽走(不支持过渡方向)
         rippleEffect //滴水效果(不支持过渡方向)
         pageCurl     //向上翻页效果
         pageUnCurl   //向下翻页效果
         cameraIrisHollowOpen  //相机镜头打开效果(不支持过渡方向)
         cameraIrisHollowClose //相机镜头关上效果(不支持过渡方向)
         */
        
        /* 过渡方向
         fromRight;
         fromLeft;
         fromTop;
         fromBottom;
         */
        
        
    }
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
       
        
        CATransition *transition = [CATransition animation];
        // 动画时间控制
        transition.duration = 0.3f;
        //动画的开始与结束的快慢
        transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        //是否代理
        transition.delegate = self;
        //此动画执行完后会自动remove,默认值为true
        transition.removedOnCompletion = NO;
        //各种动画效果
        transition.type = kCATransitionMoveIn;
        //动画方向
        transition.subtype = kCATransitionFromTop;
        
        FirstViewController *viewCon = [[FirstViewController alloc]init];
        
        [self.navigationController pushViewController:viewCon animated:NO];
        
        // 想添加CA动画的VIEW的层上添加此代码
        [self.navigationController.view.layer addAnimation:transition forKey:nil];
    
    }
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    复制代码
  • 相关阅读:
    委托事件
    委托使用(2)
    简单的文件流写读
    datalist 分页显示不用PagedDataSource对象
    委托使用(1)
    文件的路径问题
    委托揭秘
    一个简单的文件上传(没有数据库的)
    Quartz 2D 练习2多点触摸画圈
    插件框架精简版 x3py 已在Win/Mac/Linux下测试通过
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/7015731.html
Copyright © 2020-2023  润新知