zoukankan      html  css  js  c++  java
  • ios7 UIScrollView 尺寸问题

    假设在UINavigationController内设置一个UIViewControlller,而UIViewController的第一个子视图是UIScrollView的话,UIScrollview里面全部的subView都会发生下移,如图所看到的
    ios7 <wbr>UIScrollView <wbr>尺寸问题
    代码为

    - (void)viewDidLoad

    {

        [super viewDidLoad];

     

        UIScrollView *tempScroll = [[UIScrollView allocinitWithFrame:CGRectMake(064320200)];

        [tempScroll setBackgroundColor:[UIColor grayColor]];

        [tempScroll setContentSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height)];

        [self.view addSubview:tempScroll];

     

        UIButton *tempButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

        [tempButton setBackgroundColor:[UIColor redColor]];

        [tempButton setTitle:@"subView A" forState:UIControlStateNormal];

        [tempButton setFrame:CGRectMake(80080100)];

        

        NSLog(@"%d",tempScroll.subviews.count);

        [tempScroll addSubview:tempButton];

    }

    经过验证性的代码,我发现ios7有一个机制

    在navigationBar,以及statusBar都显示的情况下,Navigation的当前VC,他的VC的view的子视图树的根部的第一个子视图,假设是Scrollview的话,这个scrollview的全部子视图都会被下移64个像素。

    发现了这个机制之后,怎么去修正呢?

    修正方案有两个

    1、把scrollview的全部子视图上移64个像素。

        UIView *targetView = self.view;

        while (targetView.subviews.count >0 && ![targetView isKindOfClass:[UIScrollView class]]) {

            targetView = [targetView.subviews objectAtIndex:0];

        }

        if ([targetView isKindOfClass:[UIScrollView class]]) {

            NSLog(@"you are a scrollview");

            CGSize tempSize = ((UIScrollView *)targetView).contentSize;

            tempSize.height -= 64;

            [(UIScrollView *)targetView setContentSize:tempSize];

            for (UIView *subView in targetView.subviews) {

                CGRect tempRect = subView.frame;

                tempRect.origin.y -= 64;

                [subView setFrame:tempRect];

            }

     

        }

    2、把scrollView更改地位,是它不是子视图树的根部第一个子视图。

    - (void)viewDidLoad

    {

        [super viewDidLoad];

     

        UIView *tempBackGround = [[UIView allocinitWithFrame:self.view.bounds];

        [self.view addSubview:tempBackGround];

        

        UIScrollView *tempScroll = [[UIScrollView allocinitWithFrame:CGRectMake(064320200)];

        [tempScroll setBackgroundColor:[UIColor grayColor]];

        [tempScroll setContentSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height)];

        [self.view addSubview:tempScroll];

     

        UIButton *tempButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

        [tempButton setBackgroundColor:[UIColor redColor]];

        [tempButton setTitle:@"subView A" forState:UIControlStateNormal];

        [tempButton setFrame:CGRectMake(80080100)];

        

        NSLog(@"%d",tempScroll.subviews.count);

        [tempScroll addSubview:tempButton];


     

    }

    经过了修正如图所看到的

    ios7 <wbr>UIScrollView <wbr>尺寸问题

  • 相关阅读:
    Hive 中parse_url的使用
    作为首席架构师,我是如何选择并落地架构方案的?
    漫谈数据仓库之拉链表(原理、设计以及在Hive中的实现)
    纸上得来终觉浅
    年薪50万的大数据分析师养成记【摘抄】
    如果有人问你数据库的原理,叫他看这篇文章(完)
    开源大数据引擎:Greenplum 数据库架构分析
    【阿里在线技术峰会】李金波:企业大数据平台仓库架构建设思路
    ETL Automation完整安装方法_(元数据存放在mysql数据库)
    js定时器 离开当前页面任然执行的问题
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4470451.html
Copyright © 2011-2022 走看看