zoukankan      html  css  js  c++  java
  • ipad流水布局及其旋转界面view间隔布局调整

    控制器嵌套关系如下,ITGDealViewControllerviewUI界面中Dock其中点击按钮弹出的一个子view

    rootViewController == mianViewController --> UINavigationController -->ITGDealViewController -->UICollectionViewFlowLayout

    *****************************************************************

    ITGAppDelegate.m文件------------------------------中的设置根控制器

    -----------------------------------------------------------------

    //设置根控制器

    self.window.rootViewController = [[ITGMainViewController alloc]init];

    ITGMainViewController.m文件

    -----------------------------------------------------------------

    //创建ITGDealViewController

    ITGDealViewController *vdeal = [[ITGDealViewController alloc]init];

    [self addOneChildVc:deal];

    -(void)addOneChildVc:(UIViewController *)vc

    {

        //导航控制器UINavigationController中有其他四个子控制器

        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];

        //主控制器ITGMainViewController中有子控制器:导航控制器UINavigationController

        [self addChildViewController:nav];

        

        

    ITGDealViewController.m文件

    -----------------------------------------------------------------

        

    //重写init方法

    - (id)init

    {

        //流水布局

        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];

        //每个格子大小

        layout.itemSize = CGSizeMake(250, 250);

        //设置每一行之间的距离

        layout.minimumLineSpacing = 20;

        //调用父类的构造方法

        if ([super initWithCollectionViewLayout:layout]) {

        }

    }

        

    //ipad屏幕旋转监听方法:子控制器和根控制器有关联才能知道屏幕旋转了

        //旋转后调用的方法

    -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

    {

        //返回的是父类UICollectionViewLayout,子类是UICollectionViewFlowLayout,把返回的父类要强转成我们要用上面的子类

        //取出布局

        UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;

        

        //设置collectionView内边距 布局

        CGFloat paddingY =20;

        CGFloat paddingX = 40;

        layout.sectionInset = UIEdgeInsetsMake(paddingY, paddingX, paddingY, paddingX);

        //判断横竖屏

        if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))//在旋转后当前横屏

        {

            paddingX = (self.view.bounds.size.width - 3*layout.itemSize.width)/4;

        }else{

            paddingX = (self.view.bounds.size.width - 2*layout.itemSize.width)/3;

        }

        //添加动画

        [UIView animateWithDuration:0.5 animations:^{

            //行之间

            layout.minimumLineSpacing = paddingY;

        }];

    }

    //即将旋转调用的方法  本例没有有使用

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

    {

        

    }

        

    //想一进界面就有这样的效果,就在-(void)viewDidLoad或者- (void)viewDidAppear:(BOOL)animated调用设置界面布局效果的方法,具体调用哪个视情况而定

    [self didRotateFromInterfaceOrientation:0];

    //如本例适合调用的方法

    - (void)viewDidAppear:(BOOL)animated

    {

        [super viewDidAppear:animated];

        //调用设置界面布局效果的方法

        [self didRotateFromInterfaceOrientation:0];

    }

        

        

  • 相关阅读:
    动态规划之背包问题
    Python中import导入上一级目录模块及循环import问题的解决
    Anaconda介绍、安装及使用教程
    负载均衡基础知识
    TCP和UDP的区别(转)
    microsoft visual c++ 14.0 is required问题解决办法
    python使用requests时报错requests.exceptions.SSLError: HTTPSConnectionPool
    解决Anaconda无法更新的问题
    彻底的理解TCP协议的三次握手和四次分手
    android调试工具 adb命令学习
  • 原文地址:https://www.cnblogs.com/zuozeing/p/3563708.html
Copyright © 2011-2022 走看看