IOS开发之UIScrollVIew运用
2012-03-16 14:41
375 查看
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的最小值(位于屏幕的最左边)
[b]CGRectGetMaxX方法的作用得到目前scrollview在当前屏幕中相对于整个UIScrollView的最大值(位于屏幕的最右边)[/b]
CGRectGetMinY方法的作用得到目前scrollview在当前屏幕中相对于整个UIScrollView的最小值(位于屏幕的最上边)
[b]CGRectGetMaxY方法的作用得到目前scrollview在当前屏幕中相对于整个UIScrollView的最大值(位于屏幕的最下边)[/b]
[b]CGRectGetMaxX-CGRectGetMinX)/2)[/b]
[b]CGRectGetMaxY-CGRectGetMinY)/2)[/b]
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:
#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的最小值(位于屏幕的最左边)
[b]CGRectGetMaxX方法的作用得到目前scrollview在当前屏幕中相对于整个UIScrollView的最大值(位于屏幕的最右边)[/b]
CGRectGetMinY方法的作用得到目前scrollview在当前屏幕中相对于整个UIScrollView的最小值(位于屏幕的最上边)
[b]CGRectGetMaxY方法的作用得到目前scrollview在当前屏幕中相对于整个UIScrollView的最大值(位于屏幕的最下边)[/b]
[b]CGRectGetMaxX-CGRectGetMinX)/2)[/b]
[b]CGRectGetMaxY-CGRectGetMinY)/2)[/b]
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与UIPageControl的用法
- iOS开发UI篇—UIScrollView控件简单使用
- iOS开发-UIScrollView的用法
- IOS开发之UIScrollViewDelegate详解
- IOS开发-UIScrollView陷阱之----删除所有子view, 滚动条(indicator) 消失
- iOS开发之 UIScrollView的frame、contentSize、contentOffset和contentInset属性
- iOS开发tips-UIScrollView的Autlayout布局
- IOS开发之瀑布流的实现(UICollectionView与UIScrollView)
- IOS开发之UIScrollView使用总结
- iOS开发68-iOS 如何让UIScrollView在手指离开后立即停止滑动
- 【iOS开发-107】UISplitViewController:如何取得master和detail控制器,核心在于如何运用代理
- ios开发基础--滚动视图(UIScrollView)
- iOS开发UIScrollView使用详解
- iOS开发中使用UIScrollView实现图片轮播和点击加载
- iOS开发之UIScrollView中frame、contentSize、contentOffset、contentInset
- iOS开发UI篇—UIScrollView控件实现图片缩放功能
- iOS开发——解决UIScrollView控件移动错位和无法滚动
- UIScrollView 滚动视图—IOS开发