首页 技术 正文
技术 2022年11月19日
0 收藏 484 点赞 3,171 浏览 3410 个字

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:

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898