MWPhotoBrowser - 圖片視頻查看器

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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容