UIScrollView学习笔记
1.如何使用UIScrollView显示一张比屏幕大的图片
//创建滚动视图的对象
UIScrollView * sv = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
//将图片视图添加到滚动视图的子视图
[sv addSubview:iv];
//将滚动视图添加到view上
[self.view addSubview:sv];
//contentSize:可滑动区域的大小(即这个区域内的内容是可以滑动的!scrollview的frame 表示所有可滑动的内容,都在这个frame中进行滑动)
sv.contentSize = image.size;
2.UIScrollView常用的属性和方法
//是滚动视图的左上角坐标(自身的坐标原地)相对于内容的坐标原点的偏移量
sv.contentOffset = CGPointMake(image.size.width-320, image.size.height-480);
//内容和视图的留白
sv.contentInset = UIEdgeInsetsMake(100, 100, 0, 0);
//关闭竖立,水平提示条
sv.showsHorizontalScrollIndicator = NO;
sv.showsVerticalScrollIndicator = NO;
//关闭弹簧效果
sv.bounces = NO;
//设置是否可以滚动(默认YES)
sv.scrollEnabled = YES;
//设置放大与缩小
sv.minimumZoomScale = 0.2;
sv.maximumZoomScale = 2;
===================================
UIScrollViewDelegate代理
===================================
1.UIScrollView常用的代理方法的介绍以及触发的时机
1、只要view有滚动(不管是拖、拉、放大、缩小等导致)都会执行此函数
-(void)scrollViewDidScroll:(UIScrollView *)scrollView;
2、将要开始拖拽,手指已经放在view上并准备拖动的那一刻
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
3、将要结束拖拽,手指已拖动过view并准备离开手指的那一刻,注意:当属性pagingEnabled为YES时,此函数不被调用
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset;
4、已经结束拖拽,手指刚离开view的那一刻
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
5、view将要开始减速,view滑动之后有惯性
-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;
6、view已经停止滚动
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
7、view的缩放
-(void)scrollViewDidZoom:(UIScrollView *)scrollView
8、有动画时调用
-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;