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 ...
随机推荐
- MySQL参数化查询的IN 和 LIKE
https://stackoverflow.com/questions/650455/c-sharp-parameterized-query-mysql-with-in-clausehttps://s ...
- 【Linux】&、&&、|、||的用法说明
在Linux系统中,&.&&.|.||的用法如下: & 表示任务在后台运行,例如:ping 127.0.0.1>a.txt& && 表 ...
- matplotlib01
matplotlib是基于numpy的一套Python工具包.这个包提供了丰富的数据绘图工具,可实现数据分析的可视化. 所以在安装matplotlib时,需要先安装numpy包.
- JS修改当前控件样式&为控件追加事件
先搁这吧,今天太晚了,以后再加注释和修整吧.不幸搜到的朋友就别看了 <%@ Page Language="vb" AutoEventWireup="false&qu ...
- DirectX中文手册
目 录 第一章 DirectX基础(初级篇) 第一节 什么是DirectX 一.什么是DirectX ? 二.DirectX的组成部分 三.关于DirectDraw 四.为什么要使用DirectD ...
- 数学之路-python计算实战(9)-机器视觉-图像插值仿射
插值 Python: cv2.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]]) → dst interpolation – interpol ...
- Jqeury Mobile实战之切屏效果以及屏幕滚动到底端加载更多和点击切换更多
http://blog.csdn.net/q718330882/article/details/46120691 //页面滚动到底部加载更多事件 $( window ).scroll(function ...
- ios中文件下载(带缓存)
使用asiHttPRequst框架 封装下载类 #import <Foundation/Foundation.h> #define FILESDOWNLOADCOMPLETE @" ...
- ThinkPHP+jQuery EasyUI Datagrid查询数据的简单处理
ThinkPHP和jQuery EasyUI这两个都是不错的框架,现在要把它两个整合到一块,做个简单的Ajax调用查询. 在ThinkPHP模板中引入EasyUI的相关文件,然后设置按钮3的调用: & ...
- mysql 排序 oder by 和 使用hibernate 排序
String sql="select * from sys_invitation where to_phone = '13000000000' order by create_time de ...