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,

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

    他们之间的关系:

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

  • 相关阅读:
    MUI常用脚本及原生JavaScript常用操作元素方法
    cmf5分页相关
    TP5数据库操作方法总结
    mui的选项卡js选中指定项
    thinkphp 5数据库操作
    阻止touchslider事件冒泡,防止左右滑动时出发全局滑动事件
    thinkcmf5 学习笔记
    PHP Fatal error: Call to undefined function thinkfinfo_open()
    phpstudy iis版本 php4.4.5 和 php5.6.7目录权限问题
    手机uc不支持伪元素使用animation动画;移动端background-attachment:fixed不兼容性
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/3816080.html
Copyright © 2011-2022 走看看