美文网首页IOS推送iOS
MWPhotoBrowser - 图片视频查看器

MWPhotoBrowser - 图片视频查看器

作者: 居然是村长 | 来源:发表于2016-04-25 23:08 被阅读2419次

https://github.com/mwaterfall/MWPhotoBrowser

附加了好几个其他第三方库:
1 DACirculaProgress
2 MBProgressHUD
3 SDWebImage

使用还是很简单

与系统的 tableView 差不多

  • 1 需要数据源:是 MWPhoto类 的数组。

+ (MWPhoto *)photoWithImage:(UIImage *)image;// 本地图片
+ (MWPhoto *)photoWithURL:(NSURL *)url;// URL 图片
+ (MWPhoto *)photoWithAsset:(PHAsset *)asset targetSize:(CGSize)targetSize;// 照片
+ (MWPhoto *)videoWithURL:(NSURL *)url; // 视频

@property (nonatomic, strong) NSString *caption;// 描述

@property (nonatomic, strong) NSURL *videoURL;
@property (nonatomic) BOOL emptyImage;
@property (nonatomic) BOOL isVideo;

  • 2 显示 类似TableView
- (id)initWithPhotos:(NSArray *)photosArray;// 不需要代理,直接使用预览,简单方便
- (id)initWithDelegate:(id <MWPhotoBrowserDelegate>)delegate;// 代理方法更多


@property (nonatomic) BOOL displayNavArrows;// toolBar 上的 左右翻页 ,默认 NO
@property (nonatomic) BOOL displayActionButton;// 系统分享
@property (nonatomic) BOOL alwaysShowControls;// 是否一直显示 导航栏

@property (nonatomic) BOOL displaySelectionButtons;// 选择图片
@property (nonatomic, strong) NSString *customImageSelectedIconName;// 选择大图
@property (nonatomic, strong) NSString *customImageSelectedSmallIconName;// 选择小图

@property (nonatomic) BOOL enableGrid;// 是否可以查看小图预览模式
@property (nonatomic) BOOL startOnGrid;// 以小图预览模式进入

@property (nonatomic) BOOL autoPlayOnAppear;// 自动播放视频
@property (nonatomic) NSUInteger delayToHideElements;// 延迟 隐藏时间
@property (nonatomic) BOOL zoomPhotosToFill;//

@property (nonatomic, readonly) NSUInteger currentIndex;// 当前位置

- (void)reloadData;// 重新加载
- (void)setCurrentPhotoIndex:(NSUInteger)index;// 默认选中



// push 显示!
    [self.navigationController pushViewController:browser animated:YES];

代理


// 数量
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return photos.count;
}

// 内容
- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    return [photos objectAtIndex:index];
}




// 网格视图
- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index {
    return [photos objectAtIndex:index];
}

// nav title
- (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index {
    return @"123";
}

// 已经 显示
- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index {
    NSLog(@"%zi",index);
}


// 是否选中,需要结合属性设置,同时使用 NSNumber 的数组
- (BOOL)photoBrowser:(MWPhotoBrowser *)photoBrowser isPhotoSelectedAtIndex:(NSUInteger)index {
    return [[_selections objectAtIndex:index] boolValue];
}
// 选择某个
- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index selectedChanged:(BOOL)selected {
    [_selections replaceObjectAtIndex:index withObject:[NSNumber numberWithBool:selected]];
}

1

相关文章

网友评论

  • feng_dev:是不是导入这个三方库之后之前已经用cocoapods 导入的 就要删除掉啊,不然导入了2次SDWebimage 会不会冲突啊
    feng_dev:@说了是村长 能编译
    居然是村长:@伤感的小孩 会
  • 走停2015_iOS开发:点击屏幕,返回的时候有调用方法吗
    走停2015_iOS开发:谢了,系统有方法,需要重写
    居然是村长:@走停2015 你看一下代理,有个点击,不知道是不是符合你的要求。

本文标题:MWPhotoBrowser - 图片视频查看器

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