UIScrollView

@property (nonatomic,strong) UIPageControl *pageControl;

@property (nonatomic,strong) UIScrollView *scorllView;

 //创建一个图片切换器,4张图片切换

self.scorllView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 200)];

    _scorllView.backgroundColor = [UIColor blackColor];

    [self.view addSubview:_scorllView];

    for (int i = 0; i<4; i++) {

        UIImageView *fimageView = [[UIImageView alloc]initWithFrame:CGRectMake(320*i, 0, 320, 200)];

        fimageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",i+1]];

        fimageView.tag = i+1;

        [_scorllView addSubview:fimageView];

    }

    _scorllView.pagingEnabled =YES;//设置内容按页显示

    _scorllView.showsHorizontalScrollIndicator = UIScrollViewIndicatorStyleWhite;//横向条类型

    _scorllView.contentSize = CGSizeMake(320*4, 200);//幕布大小,决定滚动的方向,若contentsize<=本身的size则无法滚动

    _scorllView.delegate = self;//服从代理

 其他常用属性:

scrollView.bounces=NO;//两侧弹簧效果

    //设置是否可以滚动   scrollView.scrollEnabled = NO;

    

    //进度条的样式

scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;

    

    //top,left,buttom,right,top和right影响纵向进度条,buttom和left影响横向进度条

    scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(10, 10, 10, 10);

    

    //边缘黑边的大小

   scrollView.contentInset = UIEdgeInsetsMake(50, 50, 50, 50);

    _scorllView.contentOffset = CGPointMake(320*2, 0);

    //放大缩小的倍数限制

    _scorllView.minimumZoomScale = 0.5;

    _scorllView.maximumZoomScale = 2;

    

    //创建pagecontrol负责每一页的控制

    self.pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, 180, 320, 5)];

    _pageControl.numberOfPages = 4;//页面总数

    [_pageControl addTarget:self action:@selector(pageChanged) forControlEvents:UIControlEventValueChanged];

    [self.view addSubview:_pageControl];

 

#pragma mark------------UIScrollerDelegate------

-(void)pageChanged{

    [self.scorllView setContentOffset:CGPointMake(320*_pageControl.currentPage, 0) animated:YES];

}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

    //获取滚动的页数,offset对应的页数

    int page = scrollView.contentOffset.x/320.0;

//    NSLog(@"x:%f page:%d",scrollView.contentOffset.x,page);

    [self.pageControl setCurrentPage:page];

}

//手指即将拖动

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{

   

}

//停止拖动

//-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {

    NSLog(@"停止拖动");

//}

//即将开始减速

-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{

/   

}

//放大缩小,使用前先设置放大缩小的倍数限制,只能对Scroller的子视图进行缩放

-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{

   UIImageView *fImageView = [scrollView viewWithTag:1];

    return fImageView;

}

//正在缩放

-(void)scrollViewDidZoom:(UIScrollView *)scrollView{

}

 

posted @ 2016-04-07 13:31  蜗牛才是大牛  阅读(158)  评论(0编辑  收藏  举报