UIScrollView

1.创建一个滚动视图(在内容的展示上,类似于浏览器)

   UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectMake(,,,)];

2.设置可展示内容的size

   sv.contentSize = CGSizeMake(,);

3.设置弹簧效果

   sv.bounces = NO;

4.设置翻页效果

   sv.pagintEnabled = YES;

5.设置水平和垂直进度条是否展示

    sv.showsHorizontalScrollIndicator = YES;

    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;

 

posted @ 2015-04-02 20:35  Angelone  阅读(102)  评论(0编辑  收藏  举报