美文网首页
github三方库前100之MWPhotoBrowser

github三方库前100之MWPhotoBrowser

作者: 3efefee71c8c | 来源:发表于2016-07-08 09:55 被阅读1361次

    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请求的图片。。转换成它自己的模型(MWPhoto)

    (一):使用

    self.photos = imageArray;            //此处需要注意的是,self.photos  存放的都是MWPhoto 对象,需要把image 和webUrl ,调用如上几个方法,转成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;//是否允许用网格查看所有图片,默认是

    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

    }

    相关文章

      网友评论

          本文标题:github三方库前100之MWPhotoBrowser

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