//初始化UIScrollView
UIScrollView *sc = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
sc.backgroundColor = [UIColor orangeColor];UIImage *image = [UIImage imageNamed:@"death"];
UIImageView *iv = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
iv.image = image;
//滚动范围: contentSize --> 要比scrollView的size大
//滚动范围一定要比scrollcview的本身大
sc.contentSize = image.size;
//偏移量: contentOffset --> 滚动到某一个位置(点)
// sc.contentOffset = CGPointMake(self.view.frame.size.width, 0);
//bounces - 弹簧效果
// sc.bounces = NO;
/**
alwaysBounceVertical - 一定会出现弹簧效果 - 纵向
alwaysBounceHorizontal - 横向 */
sc.alwaysBounceVertical = YES;
sc.alwaysBounceHorizontal = NO;
//关闭或者开启滚动提示器
//showsVeVrticalScrollIndicator - 纵向
//showsHorizontalScrollIndicator - 横向
sc.showsVerticalScrollIndicator = NO;
sc.showsHorizontalScrollIndicator = NO;
//是否进行滚动
// sc.scrollEnabled = NO;
//设置代理:
@interface ViewController ()<UIScrollViewDelegate>
sc.delegate = self;
//1.SCrollView的放大缩小设定
//min - 最小
//max - 最大
//scale 放大缩小倍数 , 默认是1
sc.minimumZoomScale = 0.3;
sc.maximumZoomScale = 3;
// 返回一个放大或者缩小的视图
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{ }
// 开始放大或者缩小
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view{ }
// 缩放结束时
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{ }
// 视图已经放大或缩小
- (void)scrollViewDidZoom:(UIScrollView *)scrollView{NSLog(@"scrollViewDidScrollToTop");} */
// 是否支持滑动至顶部
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView{ return YES;}
// 滑动到顶部时调用该方法
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{ NSLog(@"scrollViewDidScrollToTop");}
// scrollView 已经滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ NSLog(@"scrollViewDidScroll");}
// scrollView 开始拖动
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ NSLog(@"scrollViewWillBeginDragging");}
// scrollView 结束拖动
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ NSLog(@"scrollViewDidEndDragging");}
// scrollView 开始减速(以下两个方法注意与以上两个方法加以区别)
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{ NSLog(@"scrollViewWillBeginDecelerating");}
// scrollview 减速停止
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ NSLog(@"scrollViewDidEndDecelerating"); }