ios7 UIScrollView 尺寸问题
假设在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 尺寸问题的更多相关文章
- iOS7中弹簧式列表的制作
本文转载至 http://www.devdiv.com/forum.php?mod=viewthread&tid=208170&extra=page%3D1%26filter%3Dty ...
- UINavigationController + UIScrollView组合,视图尺寸的设置探秘(一)
UINavigationController和UIScrollView是iOS下几种主要的交互元素,但当我搭配二者在一起时,UIScrollView的滚动区域出现了很诡异的现象.我希望UIScroll ...
- IOS7官方推荐图标和图像尺寸
图标和图像大小 每一个应用程序需要一个应用程序图标和启动图像.此外,一些应用程序需要自定义的图标来表示特定于应用程序的内容,功能,或在导航栏,工具栏和标签栏模式. 不像其他的定制艺术品在您的应用程序的 ...
- UINavigationController + UIScrollView组合,视图尺寸的设置探秘(三)
还是在苹果的 View Controller Catalog for iOS 文章中找到答案.文中提到了两点: 1.If the navigation bar or toolbar are visib ...
- UINavigationController + UIScrollView组合,视图尺寸的设置探秘(二)
承接上文,我想把view布局修改为如下模式,让ScrollView长在NavigationBar的下方,这总不会有遮挡的问题了吧: story board内容如下,主要是右侧视图蓝色区域添加了Scro ...
- 你真的了解UIScrollView吗?
一:首先查看一下关于UIScrollView的定义 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIScrollView : UIView <NSCoding& ...
- 内外分离接口依赖及UIScrollView知识点
1:Class Extension 还能巧妙的解决一个接口暴露问题 有些属性或者方法对外可以提供,有些只针对内部的类进行调用: // Sark.framework/Sark.h @interface ...
- iOS-scrollview及其子类适配iOS7
问题描述: 在iOS7之后如果在导航控制器中所属的字控制器中嵌入scrollview及其子类的视图,当scrollview的尺寸太小的话不会调用返回cell的方法.控制器的嵌套层级结构如下图所示,着重 ...
- UIScrollView的封装
UIScrollView的封装 效果 特点 1.用法简单,尺寸大小,随意设置位置 2.可以有多个数据源的数据,可以定制不通的界面(如同上图,一个有文字,一个没有文字) 3.能够实现点击事件 用法 1. ...
随机推荐
- python递归函数下不能正常使用yield
# -*- coding:utf-8 -*- import os import time file_list = [] def findFile(path): listFile = os.listdi ...
- Unicode字符列表
注:除非有特别指明,否则以下符号皆属“半角”而非“全角”. 代码 显示 描述 U+0020 空格 U+0021 ! 叹号 U+0022 " 双引号 U+0023 # 井号 U+0024 $ ...
- 【转】 UIButton上使用UIEdgeInsetsMaketitle跟图片对齐
[转]http://blog.csdn.net/yanxiaoqing/article/details/7230660 默认情况下,不设置的效果,都使居中现实,button为150*150 使用以下设 ...
- Referrer 还是 Referer?
上回我写了一篇文章介绍「Referrer Policy」,有小伙伴看完后问我:Referrer 这个单词到底怎么拼,为什么有时候中间有两个 r,有时候只有一个? 是的,这是一个很有趣的问题,这里就给有 ...
- String类的实现,内部采用字符数组实现
#include <iostream> using namespace std; class String{ public: String(const char *str = NULL); ...
- 在iOS当中发送电子邮件和短信
iOS实现发送电子邮件的方法很简单,首先导入MessageUI.framework框架,然后代码如下: #import "RPViewController.h" //添加邮件头文件 ...
- LeetCode第四题,Add Two Numbers
题目原文: You are given two linked lists representing two non-negative numbers. The digits are stored in ...
- 一个可无限伸缩且无ABA问题的无锁队列
关于无锁队列,详细的介绍请参考陈硕先生的<无锁队列的实现>一文.然进一步,如何实现一个不限node数目即能够无限伸缩的无锁队列,即是本文的要旨. 无锁队列有两种实现形式,分别是数组与链表. ...
- SQL学习之用通配符进行数据过滤
一.Like操作符 之前介绍的所有的操作符都是针对已知值进行过滤.不管匹配一个值还是多个值,检验大于还是小于已知值,或者检查某个范围的值,其共同点是过滤中使用的值都是已知的. 但是这种方法并不是任何时 ...
- 关于bootstrap弹出二级对话框的使用
弹出二级对话框,即在对话框的基础上再弹出一个对话框.这对于CRM管理类系统来说应用场景很常见.看到网上有关于实现二级弹出框的方法,需要在一级对话框页面上添加不少css样式.其实,完全可以不用这么麻烦. ...