• [翻译] GMCPagingScrollView


    GMCPagingScrollView

    https://github.com/GalacticMegacorp/GMCPagingScrollView

    GMCPagingScrollView is a UIView containing a horizontally scrolling paging UIScrollView that supports page preloading, page dequeueing, and infinite scrolling.

    GMCPagingScrollView是一个UIView,包含了一个水平方向翻页滚动的UIScrollView,支持预加载,重用以及无线滚动.

    demo中提供的源码:

    #import "DemoViewController.h"
    #import "GMCPagingScrollView.h"
    
    static NSString * const kPageIdentifier = @"Page";
    
    @interface DemoViewController () <GMCPagingScrollViewDataSource, GMCPagingScrollViewDelegate>
    
    @property (nonatomic, strong) GMCPagingScrollView *pagingScrollView;
    
    @end
    
    @implementation DemoViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        self.pagingScrollView = [[GMCPagingScrollView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        self.pagingScrollView.center = self.view.center;
        self.pagingScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        self.pagingScrollView.dataSource = self;
        self.pagingScrollView.delegate   = self;
        self.pagingScrollView.infiniteScroll = YES;
        self.pagingScrollView.interpageSpacing = 0;
        [self.view addSubview:self.pagingScrollView];
        
        [self.pagingScrollView registerClass:[UIView class] forReuseIdentifier:kPageIdentifier];
        
        [self.pagingScrollView reloadData];
    }
    
    #pragma mark - GMCPagingScrollViewDataSource
    
    - (NSUInteger)numberOfPagesInPagingScrollView:(GMCPagingScrollView *)pagingScrollView {
        return 3;
    }
    
    - (UIView *)pagingScrollView:(GMCPagingScrollView *)pagingScrollView pageForIndex:(NSUInteger)index {
        UIView *page = [pagingScrollView dequeueReusablePageWithIdentifier:kPageIdentifier];
        
        switch (index) {
            case 0:
                page.backgroundColor = [UIColor redColor];
                break;
            case 1:
                page.backgroundColor = [UIColor greenColor];
                break;
            case 2:
                page.backgroundColor = [UIColor blueColor];
                break;
        }
        
        return page;
    }
    
    - (void)pagingScrollViewDidScroll:(GMCPagingScrollView *)pagingScrollView
    {
        NSLog(@"x = %f", pagingScrollView.scrollView.contentOffset.x);
    }
    
    @end

    效果:

    修改一下并使用SDWebImage来测试:

    #import "DemoViewController.h"
    #import "GMCPagingScrollView.h"
    #import "SDWebImage.h"
    
    static NSString * const kPageIdentifier = @"Page";
    
    @interface DemoViewController () <GMCPagingScrollViewDataSource, GMCPagingScrollViewDelegate>
    
    @property (nonatomic, strong) GMCPagingScrollView *pagingScrollView;
    @property (nonatomic, strong) NSArray             *dataArray;
    
    @end
    
    @implementation DemoViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.view.backgroundColor = [UIColor blackColor];
        
        _dataArray = 
        @[@"http://img4.duitang.com/uploads/item/201307/29/20130729153409_YCfU2.thumb.200_0.jpeg",
          @"http://cdn.duitang.com/uploads/item/201212/08/20121208141407_3YGMi.thumb.200_0.jpeg",
          @"http://cdn.duitang.com/uploads/item/201308/26/20130826211332_WZ4is.thumb.200_0.jpeg",
          @"http://img4.duitang.com/uploads/item/201301/21/20130121223918_aFk4h.thumb.200_0.jpeg",
          @"http://img4.duitang.com/uploads/item/201309/15/20130915114846_nsy2A.thumb.200_0.jpeg",
          @"http://cdn.duitang.com/uploads/item/201306/20/20130620142009_X3fv3.thumb.200_0.jpeg",
          @"http://img4.duitang.com/uploads/item/201306/17/20130617202501_Z2ZNP.thumb.200_0.jpeg",
          @"http://img4.duitang.com/uploads/item/201201/23/20120123181139_EvHrc.thumb.200_0.jpg",
          @"http://img4.duitang.com/uploads/item/201108/24/20110824232929_T85Zt.thumb.200_0.jpg",
          @"http://cdn.duitang.com/uploads/blog/201308/06/20130806213223_Q2Jfj.thumb.200_0.jpeg",
          @"http://cdn.duitang.com/uploads/item/201311/10/20131110141543_UMV24.thumb.200_0.jpeg",
          @"http://cdn.duitang.com/uploads/item/201307/18/20130718225516_RBMnr.thumb.200_0.jpeg",
          @"http://img4.duitang.com/uploads/item/201202/05/20120205163116_x2F4E.thumb.200_0.jpg",
          @"http://img4.duitang.com/uploads/item/201202/19/20120219150016_r48NA.thumb.200_0.jpg",];
        
        self.pagingScrollView = [[GMCPagingScrollView alloc] initWithFrame:self.view.bounds];
        self.pagingScrollView.dataSource = self;
        self.pagingScrollView.delegate   = self;
        self.pagingScrollView.infiniteScroll = YES;
        self.pagingScrollView.interpageSpacing = 0;
        [self.view addSubview:self.pagingScrollView];
        
        [self.pagingScrollView registerClass:[UIImageView class]
                          forReuseIdentifier:kPageIdentifier];
        
        [self.pagingScrollView reloadData];
    }
    
    #pragma mark - GMCPagingScrollViewDataSource
    
    - (NSUInteger)numberOfPagesInPagingScrollView:(GMCPagingScrollView *)pagingScrollView {
        return [_dataArray count];
    }
    
    - (UIView *)pagingScrollView:(GMCPagingScrollView *)pagingScrollView pageForIndex:(NSUInteger)index {
        UIImageView *page = [pagingScrollView dequeueReusablePageWithIdentifier:kPageIdentifier];
        
        [page setImageWithURL:[NSURL URLWithString:_dataArray[index]]];
        page.contentMode = UIViewContentModeScaleAspectFit;
        page.layer.masksToBounds = YES;
        
        return page;
    }
    
    - (void)pagingScrollViewDidScroll:(GMCPagingScrollView *)pagingScrollView
    {
        NSLog(@"x = %f", pagingScrollView.scrollView.contentOffset.x);
    }
    
    @end

  • 相关阅读:
    LOJ-10108(欧拉回路+并查集)一个图至少用几笔画成
    hdu-1878(欧拉回路)
    LOJ-10106(有向图欧拉回路的判断)
    欧拉回路
    LOJ-10105(欧拉回路模板,套圈法,递归)
    LOJ-10102(求A到B之间的割点)
    LOJ-10103(求删去割点后最多的连通分量)
    LOJ-10102(桥的判断)
    【XSY2278】【HDU5669】the Red Sun(线段树+dijkstra)
    【XSY2434】【CF787D】遗产(线段树+dijkstra)
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/3746970.html
Copyright © 2020-2023  润新知