美文网首页第三方集成
SDPhotoBrowser图片查看器的简单使用

SDPhotoBrowser图片查看器的简单使用

作者: hncjliyingjie | 来源:发表于2017-02-15 15:12 被阅读564次

    导入头文件

    #import "ApplyJobDetailTableViewCell.h"

    #import "SDPhotoBrowser.h"

    遵循代理

    @interface ApplyJobDetailTableViewCell ()<SDPhotoBrowserDelegate>

    创建SDPhotoBrowser

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

    SDPhotoBrowser *browser = [[SDPhotoBrowser alloc] init];

    browser.currentImageIndex = indexPath.item;

    browser.sourceImagesContainerView = self.collectionView;

    browser.imageCount = _jobModel.file.count;

    browser.delegate = self;

    [browser show];

    }

    //实现协议方法

    - (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index {

    UIImage *image = [UIImage imageNamed:@"gengduo"];

    return image;

    }

    - (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index {

    return [NSURL URLWithString:[NSString stringWithFormat:@"%@", _jobModel.file[index]]];

    }

    其中有个坑,因为第一次使用没有经验,就入坑了.在设置sourceImagesContainerView这个属性的时候,必须是UIView,而且必须是图片集存放在的view上.所以这里我刚开始设置

    browser.sourceImagesContainerView = self 

    相当于设置cell为这个sourceImagesContainerView了,但是这里查看第三章图片往后就会崩溃.所以正确的设置方式应该是

    browser.sourceImagesContainerView = self.collectionView;

    相关文章

      网友评论

        本文标题:SDPhotoBrowser图片查看器的简单使用

        本文链接:https://www.haomeiwen.com/subject/qqeqwttx.html