IOS开发之UIScrollVIew运用
UIScrollView可以实现在一个界面看到所有内容,同时也不需要担心所显示的内容超出屏幕的大小,当超出之后可以翻阅至下一页浏览。
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { //在UIScrollView滑动的时候调用此代理函数
CGRect visibleBounds = scrollView.bounds; //得到当前UIScrollView在屏幕中显示区域相对于scrollview的位置
NSLog(@"%lf, %lf, %lf, %lf", visibleBounds.origin.x, visibleBounds.origin.y, visibleBounds.size.width, visibleBounds.size.height);
NSLog(@"%lf, %lf", CGRectGetMinX(visibleBounds), CGRectGetMaxX(visibleBounds));
int firstNeededPageIndex = floorf(CGRectGetMinX(visibleBounds) / CGRectGetWidth(visibleBounds));
int lastNeededPageIndex = floorf((CGRectGetMaxX(visibleBounds)-1) / CGRectGetWidth(visibleBounds));
NSLog(@"firsr:%d, last:%d", firstNeededPageIndex, lastNeededPageIndex);
--firstNeededPageIndex;
++lastNeededPageIndex;
firstNeededPageIndex = MAX(firstNeededPageIndex, 0);
lastNeededPageIndex = MIN(lastNeededPageIndex, 7);
NSLog(@"firsr:%d, last:%d", firstNeededPageIndex, lastNeededPageIndex);
/*
2012-03-16 14:22:01.531 skoda[3459:11903] 297.000000, 0.000000, 300.000000, 276.000000
2012-03-16 14:22:01.531 skoda[3459:11903] 297.000000, 597.000000
CGRectGetMinX方法的作用得到目前scrollview在当前屏幕中相对于整个UIScrollView的最小值(位于屏幕的最左边)
CGRectGetMaxX方法的作用得到目前scrollview在当前屏幕中相对于整个UIScrollView的最大值(位于屏幕的最右边)
CGRectGetMinY方法的作用得到目前scrollview在当前屏幕中相对于整个UIScrollView的最小值(位于屏幕的最上边)
CGRectGetMaxY方法的作用得到目前scrollview在当前屏幕中相对于整个UIScrollView的最大值(位于屏幕的最下边)
CGRectGetMaxX-CGRectGetMinX)/2)
CGRectGetMaxY-CGRectGetMinY)/2)
2012-03-16 14:22:01.531 skoda[3459:11903] firsr:0, last:1
2012-03-16 14:22:01.531 skoda[3459:11903] firsr:0, last:2
2012-03-16 14:22:01.547 skoda[3459:11903] 298.000000, 0.000000, 300.000000, 276.000000
2012-03-16 14:22:01.548 skoda[3459:11903] 298.000000, 598.000000
2012-03-16 14:22:01.548 skoda[3459:11903] firsr:0, last:1
2012-03-16 14:22:01.548 skoda[3459:11903] firsr:0, last:2
2012-03-16 14:22:01.564 skoda[3459:11903] 299.000000, 0.000000, 300.000000, 276.000000
2012-03-16 14:22:01.564 skoda[3459:11903] 299.000000, 599.000000
2012-03-16 14:22:01.564 skoda[3459:11903] firsr:0, last:1
2012-03-16 14:22:01.565 skoda[3459:11903] firsr:0, last:2
2012-03-16 14:22:01.581 skoda[3459:11903] 300.000000, 0.000000, 300.000000, 276.000000
2012-03-16 14:22:01.581 skoda[3459:11903] 300.000000, 600.000000
2012-03-16 14:22:01.581 skoda[3459:11903] firsr:1, last:1
2012-03-16 14:22:01.581 skoda[3459:11903] firsr:0, last:2
*/
for (int index = firstNeededPageIndex; index <= lastNeededPageIndex; index++) {
if (![self isDisplayingPageForIndex:index]) {
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(index * self.scrollView.frame.size.width, 0,self.scrollView.frame.size.width, self.scrollView.frame.size.height)];
webView.backgroundColor = [UIColor clearColor];
[self setCornerRadius:webView];
[self.scrollView addSubview:webView];
[self.visiblePages setObject:webView forKey:[NSNumber numberWithInt:index]];
[webView release];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:[kFileDirectoryPathstringByAppendingFormat:@"/service%d.html", index+1]]];
[webView loadRequest:request];
}
}
属性:
contentOffset计算内容位移
contentInset表格外面得东西
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView // 滚动停止时,触发该函数
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate //触摸屏幕并拖拽画面,再松开,最后停止时,触发该函数
// 调用以下函数,来自动滚动到想要的位置,此过程中设置有动画效果,停止时,触发该函数
setContentOffset:animated:
scrollRectToVisible:animated:
scrollToRowAtIndexPath:atScrollPosition:animated:
selectRowAtIndexPath:animated:scrollPosition:
scrollViewDidEndScrollingAnimation:
IOS开发之UIScrollVIew运用的更多相关文章
- IOS开发之UIScrollView约束布局
概要 在iOS开发学习中,UIScrollView是绕不过去的一个重要控件. 但是相对于Android的ScrollView,iOS的这个滚动控件的用法简直是复杂一万倍... 最主要是目前能找到的大部 ...
- iOS开发之 UIScrollView的frame、contentSize、contentOffset和contentInset属性
ios中下拉图片变大效果 http://blog.csdn.net/mad2man/article/details/14169197 IOS中UIScrollView的frame.contentSiz ...
- IOS开发之UIScrollView
一.UIScrollView的边界处理问题: bounds属性: (1)当bounces属性设置为YES时,当UIScrollView中图片滑动到边界的时候会出现弹动的效果,就像是Linux中的果冻效 ...
- 李洪强iOS开发之RunLoop的原理和核心机制
李洪强iOS开发之RunLoop的原理和核心机制 搞iOS之后一直没有深入研究过RunLoop,非常的惭愧.刚好前一阵子负责性能优化项目,需要利用RunLoop做性能优化和性能检测,趁着这个机会深入研 ...
- iOS开发之Socket通信实战--Request请求数据包编码模块
实际上在iOS很多应用开发中,大部分用的网络通信都是http/https协议,除非有特殊的需求会用到Socket网络协议进行网络数 据传输,这时候在iOS客户端就需要很好的第三方CocoaAsyncS ...
- iOS开发之UISearchBar初探
iOS开发之UISearchBar初探 UISearchBar也是iOS开发常用控件之一,点进去看看里面的属性barStyle.text.placeholder等等.但是这些属性显然不足矣满足我们的开 ...
- iOS开发之UIImage等比缩放
iOS开发之UIImage等比缩放 评论功能真不错 评论开通后,果然有很多人吐槽.谢谢大家的支持和关爱,如果有做的不到的地方,还请海涵.毕竟我一个人的力量是有限的,我会尽自己最大的努力大家准备一些干货 ...
- iOS开发之 Xcode6 添加xib文件,去掉storyboard的hello world应用
iOS开发之 Xcode6.1创建仅xib文件,无storyboard的hello world应用 由于Xcode6之后,默认创建storyboard而非xib文件,而作为初学,了解xib的加载原理 ...
- iPhone开发之UIScrollView初步
来源:http://blog.csdn.net/htttw/article/details/7891396 iPhone开发之UIScrollView初步 今天我们初步介绍以一下iPhone开发中的U ...
随机推荐
- std::accumulate使用的一个小细节
今天使用std::accumulate模板函数的时候出现了一个错误,特此记录一下. #include <iostream> #include <numeric> int mai ...
- 移植到windows下的iconv
This is a short memo about installing iconv on Windows host (specifically: Windows 7 SP1 x64). Iconv ...
- chrome配置文件校验初始化隐含參数的逆向
这篇文章接上一篇文章进一步升华:花了4个小时获得该信息的计算方式 比方在 chrome文件夹下的\Chrome\User Data\Default文件夹下的Secure Preferences,须要 ...
- C#正则验证字符串是否全是数字
Regex r = new Regex(@"^\d+$"); if (r.Match(vlannumber).Success) { sql += " and a.vlan ...
- 你想要的iOS 小技巧总结
UITableView的Group样式下顶部空白处理 //分组列表头部空白处理 UIView *view = [[UIView alloc] initWithFrame:CGRectMake(, , ...
- linux c学习笔记----线程创建与终止
进程原语 线程原语 描述 fork pthread_create 创建新的控制流 exit pthread_exit 从现有的控制流中退出 waitpid pthread_join 从控制流中得到退出 ...
- C++的iostream标准库介绍+使用详解(转)
0 为什么需要iostream 我们从一开始就一直在利用C++的输入输出在做着各种练习,输入输出是由iostream库提供的,所以讨论此标准库是有必要的,它与C语言的 stdio库不同,它从一开始就是 ...
- VC学习笔记:状态栏
原文链接: http://www.cnblogs.com/skyseraph/archive/2010/11/27/1889952.html 实例学习 1 新建对话框程序 2 为Dlg类添加成员变 ...
- [Perforce]password (P4PASSWD) invalid or unset. 的错误解决
前言 使用 Perforce , 能够使用Perforce 的Client 端. 有时候在编写一些脚本或代码的时候, 可能或使用到 Perforce的命令的方式. 正常状况下. 使用例如以下命令: p ...
- 题目要求:将a,b两个数的值进行交换,并且不使用任何的中间变量。
a = a+b; b = a-b; a = a-b;