iphone/ipad关于size, frame and bounds总结和UIScroll view学习笔记
1. iphone/ipad大小
| Device | Screen dimensions(in points) |
| iphone and ipod | 320 X 480 |
| ipad | 768 X 1024 |
2. UIScreen bounds and applicationFrame
[UISCreen mainScreen].bounds, 永远返回portait模式的width/height, 也就是说width:320 height:480 for iPhone
[UISCreen mainScreen].applicationFrame更加复杂一些,它考虑了status bar的高度。
portait模式, x:0, y:20, width:320, height:460
landscape, x:20, y:0, width:300, height:480
关于frame和bounds的区别,请参考UIView中的frame和bounds属性的区别
3. status bar height: 20, tool bar height: 44, tab bar height:44
4. UIScrollView
- contentSize和contentInSet

- contentOffSet:

// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets; // If active text field is hidden by keyboard, scroll it so it's visible
// Your application might not need or want this behavior.
CGRect aRect = self.view.frame;
aRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(aRect, activeField.frame.origin) ) { //判断该text field是否在可见区域
CGPoint scrollPoint = CGPointMake(0.0, instance); //这里需要计算需要scroll的长度,假设instance是计算出来的结果。
[scrollView setContentOffset:scrollPoint animated:YES];
}
}
- UIScroll view使用翻页模式
原文来自这里, 这里介绍几个关键的内容:
1. pagingMode需要设置为YES
2. contentSize是所有页数的width总和, 例如你需要显示100页,那contentSize的宽度就是100*scroll.frame.size.width
3. showsHorizontalScrollIndicator和showsVerticalScrollIndicator设置为NO
然后需要在scroll view的delegate中实现scrollViewDidScroll:方法,这个方法在scroll view的contentOffSet发生变化的时候被调用。翻页模式的核心思想就是scroll view需要显示下一页的时候,创建一个view, 在这个view上准备好数据,然后把这个view加到scroll view当前显示的位置。
代码如下所示,另外还可以改进的一个地方是需要翻页之前,需要把后面一页的内容也显示出来,否则会有一半黑的屏幕显示。
-(void) loadPageView:(NSUInteger)page
{
UIView* view = [[UIView alloc] init];
view.backgroundColor = [UIColor whiteColor]; CGRect rc = self.view.frame;
rc.origin.y = 0;
rc.origin.x = page * self.view.frame.size.width; //创建一个view,调整x直,因为其他直和scroll view都是一样的
view.frame = rc; UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, rc.size.width, 40)];
label.text = [NSString stringWithFormat:@"current page is :%d", page];
[view addSubview:label]; [(UIScrollView*)self.view addSubview:view];
} - (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.x >= (myCurrentPage+0.5) * self.view.frame.size.width) //需要显示下一页了
{
myCurrentPage++;
[self loadPageView:myCurrentPage];
}
}
iphone/ipad关于size, frame and bounds总结和UIScroll view学习笔记的更多相关文章
- iOS--------坐标系统(UIView的frame、bounds跟center属性)
1.概要翻开ios官方开发文档,赫然发现上面对这三个属性的解释如下: frame:描述当前视图在其父视图中的位置和大小. bounds:描述当前视图在其自身坐标系统中的位置和大小. center:描述 ...
- ios基础之 view的frame 与 bounds 的区别 (转)
前言: 学习ios开发有一段时间了,项目也做了两个了,今天看视频,突然发现view的frame和bound两个属性,发现bound怎么也想不明白,好像饶你了死胡同里,经过一番尝试和思考,终于弄明白bo ...
- frame和bounds区别
学习ios开发有一段时间了,项目也做了两个了,今天看视频,突然发现view的frame和bound两个属性,发现bound怎么也想不明白,好像饶你了死胡同里,经过一番尝试和思考,终于弄明白bound的 ...
- frame和bounds的区别与联系
首先先看一下下面两个属性的代码实现: -(CGRect)frame{ return CGRectMake(self.frame.origin.x,self.frame.origin.y,self.fr ...
- iOS 中的frame,bounds,center,transform关联
这里有一篇好文章 http://www.winddisk.com/2012/06/07/transform/ 先看几个知识点,UIView 的frame,bounds,center,transform ...
- 《View Programming Guide for iOS》之frame、bounds和center之间的关系
The frame property contains the frame rectangle, which specifies the size and location of the view i ...
- ios view的frame和bounds之区别(位置和大小)
前言: 学习ios开发有一段时间了,项目也做了两个了,今天看视频,突然发现view的frame和bound两个属性,发现bound怎么也想不明白,好像饶你了死胡同里,经过一番尝试和思考,终于弄明白bo ...
- iOS开发——使用OC篇&frame,bounds,center,position,anchorPoint总结
frame,bounds,center,position,anchorPoint总结 图层的 position 属性是一个 CGPoint 的值,它指定图层相当于它父图层的位置, 该值基于父图层的坐标 ...
- 深入探究frame和bounds的区别以及setbounds使用
[转自]http://blog.csdn.net/hherima/article/details/39501857 在iOS开发中经常遇到两个词Frame和bounds,本文主要阐述Frame和bou ...
随机推荐
- 一道 JavaScript 面试题
有一道 JavaScript 面试题. f = function () { return true; }; g = function () { return false; }; (function() ...
- sort函数CCF
题是比较水的啦,但是好久没有用sort函数啦,有点生疏^...^ #include<stdio.h> #include<string.h> #include<iostre ...
- 使用virtualbox安装centos虚拟机,以及VirtualBox无法安装64位Linux CentOS的解决办法
之前一直用vmware的虚拟机,好吧,其实一直盗版挺不好的,然后想用centos搭点东西,结果在vmare上安装centos总是有些问题,看了人给的建议换用virtualbox,虽然virtualbo ...
- tesseract-orc 合并识别结果
在实际使用 tesseract-orc 识别库的时候,初次制作的识别库很有可能识别率不太理想,需要后期慢慢补充 本文演示如何将多个修正过的box文件合并成一个识别库. 首先,需要图片样本.tif文件, ...
- Flex4/AS3.0自定义VideoPlayer组件皮肤,实现Flash视频播放器
要求 必备知识 本文要求基本了解 Adobe Flex编程知识. 开发环境 Flash Builder4/Flash Player11 演示地址 演示地址 资料下载 Adobe Flash Pla ...
- Change screensaver through registry
If you wanna change the screensaver, you can update registry as follows{autoit script}: RegWrite(&qu ...
- 洛谷P1984 SDOI2008烧水问题
P1984 [SDOI2008]烧水问题 186通过 438提交 题目提供者lych 标签数论(数学相关)模拟各省省选 难度普及+/提高 提交该题 讨论 题解 记录 最新讨论 求助! 也是醉了... ...
- 使用VS2012生成DLL文件 (1)
一:生成DLL 1:创建DLL工程 文件->新建->项目->visual c++->win32->win32控制台应用程序(win32项目也可以) 填写项目名称MyDLL ...
- SVN与TortoiseSVN实战:冲突详解(一)
硬广:<SVN与TortoiseSVN实战>系列已经写了三篇,第一篇<SVN与TortoiseSVN实战:从入门到精通>,第二篇<SVN与TortoiseSVN实战:标签 ...
- hbase日常运维管用命令,region管理
1 Hbase日常运维 1.1 监控Hbase运行状况 1.1.1 操作系统 1.1.1.1 IO 群集网络IO,磁盘IO,HDFS IO IO越大说明文件读 ...