zoukankan      html  css  js  c++  java
  • UIWindow,UINavigationController与UIViewController之间的关系

    UIWindow,UINavigationController与UIViewController之间的关系

    虽然每次你都用UINavigationController与UIWindow,但你不一定知道他们之间到底怎么运作的哦:)

    AppDelegate.h的代码

    RootViewController.m

    //
    //  RootViewController.m
    //  UIWindow
    //
    //  Copyright (c) 2014年 Y.X. All rights reserved.
    //
    
    #import "RootViewController.h"
    
    #define VALUE  1
    
    @interface RootViewController ()
    
    @end
    
    @implementation RootViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.view.backgroundColor = [UIColor redColor];
        
        UITapGestureRecognizer *tap = 
        [[UITapGestureRecognizer alloc] initWithTarget:self
                                                action:@selector(tapEvent:)];
        
        [self.view addGestureRecognizer:tap];
    }
    
    - (void)tapEvent:(UITapGestureRecognizer *)gesture
    {
        static int flag = 1;
        if (flag)
        {
            // 初始化3D变换,获取默认值
            CATransform3D perspectiveTransform = CATransform3DIdentity;
            
            // 缩放变换
            perspectiveTransform = CATransform3DScale(perspectiveTransform, 0.75, 0.75, 0.75);
            
            [UIView animateWithDuration:0.3 animations:^{
                if (VALUE)
                {
                    // 导航控制器的view
                    self.navigationController.view.transform = 
                        CATransform3DGetAffineTransform(perspectiveTransform);
                }
                else
                {
                    // 自身controller的view
                    self.view.transform = CATransform3DGetAffineTransform(perspectiveTransform);
                }
            }];
            
            flag = 0;
        }
        else
        {
            // 初始化3D变换,获取默认值
            CATransform3D perspectiveTransform = CATransform3DIdentity;
            
            // 缩放变换
            perspectiveTransform = CATransform3DScale(perspectiveTransform, 1, 1, 1);
            
            [UIView animateWithDuration:0.3 animations:^{
                if (VALUE)
                {
                    // 导航控制器的view
                    self.navigationController.view.transform = 
                        CATransform3DGetAffineTransform(perspectiveTransform);
                }
                else
                {
                    // 自身controller的view
                    self.view.transform = CATransform3DGetAffineTransform(perspectiveTransform);
                }
            }];
            
            flag = 1;
        }
    }
    
    @end

    VALUE = 1 的时候与 VALUE = 0 的时候

    他们的关系其实非常简单.

    UIWindow  ---> UINavigationController  --->  UIViewController,

    有时候,我们需要做缩放动画的效果,或者是转场动画的效果,不理解他们之间细微的差距,是没办法处理好的.

    他们之间的关系:

    知道了这些原理,再写一个侧边栏,实在是太简单了:).

  • 相关阅读:
    PHP实现html字符实体转汉字
    利用 secureCRT 直接上传下载文件 (sz,rz)
    CentOS安装scp命令
    以Apache模块的方式编译安装php-5.5.4
    编译安装 apache 2.4.6
    协方差Covariance的表述推导
    Java _ JDK _ Arrays, LinkedList, ArrayList, Vector 及Stack
    Java_一些特殊的关键字详(?)解
    Java_你应该知道的26种设计模式
    排序与搜索一览
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/3816080.html
Copyright © 2011-2022 走看看