MWPhotoBrowser ?一款可以加載web Image對象的圖片游覽器. ?下面介紹它的使用糖赔,以及自定義他的UI滔驾。
+ (MWPhoto *)photoWithImage:(UIImage *)image; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //加載的image對象
+ (MWPhoto *)photoWithURL:(NSURL *)url; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//加載請求web獲得的圖片
+ (MWPhoto *)photoWithAsset:(PHAsset *)asset targetSize:(CGSize)targetSize; ? ? ? ? ? ? ? ? ? ? //加載相冊圖片對象
+ (MWPhoto *)videoWithURL:(NSURL *)url; // Initialise video with no poster image ? ? ? ? ? ? ? //加載視頻對象
在使用的時候每次加載康愤。秩仆。會講 ?image對象操漠,獲取web請求的圖片业汰。伙窃。轉(zhuǎn)換成它自己的模型(MWPhoto)
(一):使用
self.photos = imageArray;? ? ? ? ? ? //此處需要注意的是,self.photos? 存放的都是MWPhoto 對象样漆,需要把image 和webUrl 为障,調(diào)用如上幾個方法,轉(zhuǎn)成MWPhoto 放祟。鳍怨。如 :
MWPhoto *photo, *thumb;
photo = [MWPhoto photoWithImage:image]; 。舞竿。京景。photo = [MWPhoto photoWithImage:image(httpUrl)];
photo.caption = @"此處設置圖片標題骗奖,顯示在屏幕下方";
MWPhotoBrowser ?*browser = [[MWPhotoBrowser alloc]initWithDelegate:self];?
browser.displayActionButton =NO;//分享按鈕,默認是
browser.displayNavArrows = NO;//左右分頁切換,默認否<屏幕下方的左右角標>
browser.displaySelectionButtons = NO;//是否顯示選擇按鈕在圖片上,默認否
browser.alwaysShowControls = NO;//控制條件控件 是否顯示,默認否
browser.zoomPhotosToFill = NO;//是否全屏,默認是
browser.enableGrid = NO;//是否允許用網(wǎng)格查看所有圖片,默認是
browser.enableSwipeToDismiss = NO;
[browser showNextPhotoAnimated:YES];
[browser showPreviousPhotoAnimated:YES];
[browser setCurrentPhotoIndex:0];
[Controller.navigationController pushViewController:browser animated:NO];
(二)代理方法 ?這里需要注意的是确徙,需要加上代理方法。才能夠正常使用圖片游覽
#pragma mark - MWPhotoBrowserDelegate- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {??
? return _photos.count;
}
- (id)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
if (index < _photos.count)
return [_photos objectAtIndex:index];
return nil;
}
- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index {
NSLog(@"Did start viewing photo at index %lu", (unsigned long)index);
_photoBrowser = index; ? ? ? ? ?//此處滑動执桌,可以獲取到當前image 的index鄙皇,從而自己處理
}
- (MWCaptionView *)photoBrowser:(MWPhotoBrowser *)photoBrowser captionViewForPhotoAtIndex:(NSUInteger)index{
MWPhoto *photo = [self.photos objectAtIndex:index];
MWCaptionView *captionView = [[MWCaptionView alloc] initWithPhoto:photo];
return captionView; ? ? ? ?//此方法可以定制圖片游覽頁下邊的toorBar
}