假设在UINavigationController内设置一个UIViewControlller,而UIViewController的第一个子视图是UIScrollView的话,UIScrollview里面全部的subView都会发生下移,如图所看到的

代码为

- (void)viewDidLoad

{

[super viewDidLoad];

UIScrollView *tempScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, 320, 200)];

[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(80, 0, 80, 100)];

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 alloc] initWithFrame:self.view.bounds];

[self.view addSubview:tempBackGround];

UIScrollView *tempScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, 320, 200)];

[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(80, 0, 80, 100)];

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

[tempScroll addSubview:tempButton];

}

经过了修正如图所看到的

ios7 UIScrollView 尺寸问题的更多相关文章

  1. iOS7中弹簧式列表的制作

    本文转载至 http://www.devdiv.com/forum.php?mod=viewthread&tid=208170&extra=page%3D1%26filter%3Dty ...

  2. UINavigationController + UIScrollView组合,视图尺寸的设置探秘(一)

    UINavigationController和UIScrollView是iOS下几种主要的交互元素,但当我搭配二者在一起时,UIScrollView的滚动区域出现了很诡异的现象.我希望UIScroll ...

  3. IOS7官方推荐图标和图像尺寸

    图标和图像大小 每一个应用程序需要一个应用程序图标和启动图像.此外,一些应用程序需要自定义的图标来表示特定于应用程序的内容,功能,或在导航栏,工具栏和标签栏模式. 不像其他的定制艺术品在您的应用程序的 ...

  4. UINavigationController + UIScrollView组合,视图尺寸的设置探秘(三)

    还是在苹果的 View Controller Catalog for iOS 文章中找到答案.文中提到了两点: 1.If the navigation bar or toolbar are visib ...

  5. UINavigationController + UIScrollView组合,视图尺寸的设置探秘(二)

    承接上文,我想把view布局修改为如下模式,让ScrollView长在NavigationBar的下方,这总不会有遮挡的问题了吧: story board内容如下,主要是右侧视图蓝色区域添加了Scro ...

  6. 你真的了解UIScrollView吗?

    一:首先查看一下关于UIScrollView的定义 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIScrollView : UIView <NSCoding& ...

  7. 内外分离接口依赖及UIScrollView知识点

    1:Class Extension 还能巧妙的解决一个接口暴露问题 有些属性或者方法对外可以提供,有些只针对内部的类进行调用: // Sark.framework/Sark.h @interface ...

  8. iOS-scrollview及其子类适配iOS7

    问题描述: 在iOS7之后如果在导航控制器中所属的字控制器中嵌入scrollview及其子类的视图,当scrollview的尺寸太小的话不会调用返回cell的方法.控制器的嵌套层级结构如下图所示,着重 ...

  9. UIScrollView的封装

    UIScrollView的封装 效果 特点 1.用法简单,尺寸大小,随意设置位置 2.可以有多个数据源的数据,可以定制不通的界面(如同上图,一个有文字,一个没有文字) 3.能够实现点击事件 用法 1. ...

随机推荐

  1. 安装solaris_11.2与windows双系统(VM10模拟实现)(一)

    感慨:这周刚接触solaris,装solaris很蛋疼,一个字:慢! 在上面安装软件包依然很慢,无线网也很不稳定. 在上面搭建环境更蛋疼,一个字:惨! 什么环境之类的废话就不多说了,一般的电脑都可以. ...

  2. Oracle EBS-SQL (SYS-24):职责列表

    select B.application_name, TL.responsibility_name from fnd_responsibility_tl tl, fnd_responsibility ...

  3. 奇怪的haproxy 跳转

    <pre name="code" class="html">奇怪的Haproxy 跳转: acl admin_req path_beg -i /ad ...

  4. 解析配置文件ConfigParser模块

    一.ConfigParser简介 ConfigParser 是用来读取配置文件的包.配置文件的格式如下:中括号“[ ]”内包含的为section.section 下面为类似于key-value 的配置 ...

  5. Android Afinal框架学习(二) FinalActivity 一个IOC框架

    框架地址:https://github.com/yangfuhai/afinal 相应的源代码: net.tsz.afinal.annotation.view.* FinalActivity Fina ...

  6. POJ 3692 Kindergarten (二分图 最大团)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5660   Accepted: 2756 Desc ...

  7. OS笔记047代理传值和block传值

    在两个不同的控制器之间传递数据,可以使用代理传值或者block传值. 例子是一个简单通讯录. 主界面如下: 添加联系人界面 查看/编辑联系人界面:默认是查看模式,点击编辑后进入编辑模式 编辑模式 数据 ...

  8. ObjectiveC中的block用法解析

    Block Apple 在C, Objective-C,C++加上Block这个延申用法.目前只有Mac 10.6 和iOS 4有支持.Block是由一堆可执行的程序组成,也可以称做没有名字的Func ...

  9. sql两表联合查询

    SELECT yt_fault_componentId FROM yt_fault_component a join yt_fault_assembly b on a.yt_fault_assembl ...

  10. JDK,JRE,JVM区别与联系(转)

    JDK : JavaDevelopment ToolKit(Java开发工具包).JDK是整个JAVA的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具 ...