1.建立一個滾動視圖(在內容的展現上,相似於瀏覽器)瀏覽器
UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectMake(,,,)];動畫
2.設置可展現內容的sizespa
sv.contentSize = CGSizeMake(,);字符串
3.設置彈簧效果it
sv.bounces = NO;event
4.設置翻頁效果ast
sv.pagintEnabled = YES;scroll
5.設置水平和垂直進度條是否展現im
sv.showsHorizontalScrollIndicator = YES;call
sv.showsVerticaScrollIndicator = NO;
//若是將垂直設爲NO,那麼水平進度條也就不會顯示了
6.是否容許用戶操做sv的滾動
sv.scrollEnabled = NO;
7.- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
sv.contentOffset = CGPointMake(,);//設置偏移量(經過代碼設置sv展現的區域)
[sv setContentOffset:CGPointMake(,) animate:YES];//加動畫設置偏移量
}
8.設置容許sv裏的子視圖縮放的倍數
sv.minimumZoomScale = 0.5;
sv.maximumZoomScale = 2;
9.告訴sv,容許縮放哪個子視圖
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return [scrollView.subviews lastObject];
}
10.當sv被滾動的時候調用
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"===%@",NSStringFromCGPoint(scrollView.contentOffset));
//將偏移量轉化成字符串,而後打印
}
11.- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
NSLog(@"開始拖拽");
}
12.- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
NSLog(@"結束拖拽");
}
13.- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
NSLog(@"開始滑行");
}
14.- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"結束滑行");//最經常使用
}
15.關掉vc對sv的自動調整
self.automaticallyAdjustsScrollViewInsets = NO;