UIScrollView的简单介绍

1.contentSize幕布实际大小决定滚动的方向,如果小于图片本身不滚动,默认也是不滚动

view.contentSize = CGSizeMake(1280, 200);

而frame只是用来显示UIScrollView的显示区域的大小用户看的到的。

2.页面效果,图片不可以停留在两张图中间

sview.pagingEnabled = YES;

3.是否有横向竖向滚动条,滚动条的样式黑色白色

sview.showsHorizontalScrollIndicator = NO;
sview.showsVerticalScrollIndicator = NO;
sview.indicatorStyle = UIScrollViewIndicatorStyleWhite;

4.边缘拉动弹簧效果,就是拉倒尽头的回弹效果

sview.bounces = YES;

5.设置是否可以滚动

sview.scrollEnabled = NO;

6.表示滚动指示器从封闭滚动视图中被嵌入的距离

sview.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, 0);    //四个值对应的分别是top, left, bottom, right

这个属性是相当于给scrollView在里面加了一个框,而滑动条只会在这个框上显示

7.内容滚动区域增加的距离
下拉刷新 上拉加载 滚动的时候始终有一段距离回不去

 sview.contentInset =UIEdgeInsetsMake(0, 0, 0, 0);

8.当前显示的位置

sview.contentOffset = CGPointMake(320*2, 0);
int page = scrollView.contentOffset.x/320.0;

9.常用代理方法

//滚动中
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{}
//即将开始拖动
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{} 
//即将开始减速
-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{}
//设置可以缩放的视图
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{}

10.最大放大倍数缩小倍数

sview.minimumZoomScale = 0.5;
sview.maximumZoomScale = 2;
sview.zoomScale目前拉伸的比例
//放大缩小 只能对子视图进行缩放
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
     UIImageView * iview = [scrollView viewWithTag:1];
     return iview;
}

11.pageController


self.pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, 180, 320, 20)];
self.pageControl.numberOfPages = 4;
 
self.pageControl.pageIndicatorTintColor = [UIColor grayColor];
self.pageControl.currentPageIndicatorTintColor = [UIColor lightGrayColor];
 
[_pageControl addTarget:self action:@selector(pageChanged) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:_pageControl];
 
-(void)pageChanged{
    [_sview setContentOffset:CGPointMake(320*_pageControl.currentPage, 0) animated:YES];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    int page = scrollView.contentOffset.x/320.0;
    [self.pageControl setCurrentPage:page];
}

你可能感兴趣的:(UIScrollView的简单介绍)