gitHub上面photoBrowser的使用

附上链接:https://github.com/cuzv/PhotoBrowser
最近在做一个项目,里面有一个图片浏览,类似于新浪微博里面图片浏览的效果,后来在gitHub上面找到了一个框架,很好用,在gitHub里面,可以看到how to use 第一句话就是,这个图片浏览器类似于UITableView的API,要想使用这些个方法,还要遵循photoBrowser的两个代理,下面说
  使用这个框架,要在你的项目里面
1: 导入PBViewController.h文件
2:遵循代理<<span style="color: rgb(51, 51, 51); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; background-color: rgba(0, 0, 0, 0.0392157);">PBViewControllerDataSour ce,  PBViewControllerDelegate  >
3:设置代理
4:实现代理方法
本次记录的是和collectionView以及SDWebImage一起使用的效果

#import "ViewController.h"

#import "LXCollectionViewCell.h"

#import

#import


@interface ViewController ()<</span>UICollectionViewDelegate,UICollectionViewDataSource,PBViewControllerDataSource,PBViewControllerDelegate>


@property (nonatomic,strong)NSArray *urls;


@end


@implementation ViewController


- (NSArray *)urls{

    

    if (_urls == nil) {

        

        //随便找的图片的url

        _urls = @[

                 [NSURL URLWithString:@"http://gbres.dfcfw.com/Files/picture/20160426/size500/6A27C28C515123992DC829C0142A7752.jpg"],

                 [NSURL URLWithString:@"http://img.taopic.com/uploads/allimg/120423/107913-12042323220753.jpg"],

                 [NSURL URLWithString:@"http://g.hiphotos.baidu.com/image/pic/item/03087bf40ad162d9ec74553b14dfa9ec8a13cd7a.jpg"],

                 [NSURL URLWithString:@"http://g.hiphotos.baidu.com/image/pic/item/8c1001e93901213fcea979fb51e736d12f2e957a.jpg"],

                 [NSURL URLWithString:@"http://a.hiphotos.baidu.com/image/pic/item/4b90f603738da97739bab10cb551f8198618e37b.jpg"]

                 ];

    }

    

    return _urls;

    

}


- (void)viewDidLoad {

    [super viewDidLoad];

 

    //利用xib注册一个cell

    [self.collectionView registerNib:[UINib nibWithNibName:@"LXCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"lx"];

}


#pragma mark - dataSource 这些事collectionView的代理方法

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    

    return 1;

    

}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    

    return self.urls.count;

    

}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

{

    

    //LXcollectionViewCell是自定义的cell,里面包含着一个imageview

    LXCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"lx" forIndexPath:indexPath];

    

    if (cell == nil) {

        cell = [[LXCollectionViewCell alloc]init];

    }

    

    [cell.imageviewCell sd_setImageWithURL:self.urls[indexPath.item]];

    

    return cell;

}


- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{

    

    PBViewController *pbViewController = [[PBViewController alloc]init];

    

    pbViewController.pb_dataSource = self;

    pbViewController.pb_delegate = self;

    

    [pbViewController setInitializePageIndex:indexPath.item];

    

    [self presentViewController:pbViewController animated:YES completion:nil];

    

}


#pragma mark - PBViewControllerDataSource

//这个代理方法,返回的是图片浏览器里面有几个图片

- (NSInteger)numberOfPagesInViewController:(PBViewController *)viewController {

    return self.urls.count;

}


//在这儿给图片浏览器里面的iamgeview赋值,此处采用了和SDWebImage合用

- (void)viewController:(PBViewController *)viewController presentImageView:(UIImageView *)imageView forPageAtIndex:(NSInteger)index {

    

    //这里给图片浏览器赋值图片用SDWebImage来赋值

    [imageView sd_setImageWithURL:self.urls[index]];

}


#pragma mark - PBViewControllerDelegate

//故名思议,这儿是一次点击调用的图片

- (void)viewController:(PBViewController *)viewController didSingleTapedPageAtIndex:(NSInteger)index presentedImage:(UIImage *)presentedImage {

    

    [viewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];

}


//这个是长按调用的方法

- (void)viewController:(PBViewController *)viewController didLongPressedPageAtIndex:(NSInteger)index presentedImage:(UIImage *)presentedImage {

    NSLog(@"点击了");

}

@end








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值