MJPhotoBrowser 用法

一、使用方法:
 
#import "MJPhotoBrowser.h"
#import "MJPhoto.h"
 
- ( void )tapPhoto:(UITapGestureRecognizer *)recognizer
{
    //1. 创建图片浏览器
    MJPhotoBrowser *brower = [[MJPhotoBrowser alloc] init];
   
    //2. 告诉图片浏览器显示所有的图片
    NSMutableArray *photos = [NSMutableArray array];
    for ( int i = 0 ; i < self .photos.count; i++) {
        Photo *pic = self .photos[i];
        // 传递数据给浏览器
        MJPhoto *photo = [[MJPhoto alloc] init];
        photo.url = [NSURL URLWithString:pic.bmiddle_pic];
        photo.srcImageView = self .subviews[i]; // 设置来源哪一个 UIImageView
        [photos addObject:photo];
    }
    brower.photos = photos;
   
    //3. 设置默认显示的图片索引
    brower.currentPhotoIndex = recognizer.view.tag;
   
    //4. 显示浏览器
    [brower show];
}
 
 
二、我用到的具体实例:
 
1)腾讯聊天cell中获取第几张照片,并打开图像浏览器
 
- ( void )TecentChatImageCellShouldShowFullScreen:( TecentChatImageCell *)cell
{
    MJPhotoBrowser *browser = [[ MJPhotoBrowser alloc ] init ];
   
    browser. currentPhotoIndex = [ self getPicUrl :cell. indexPath . row ]; // 获取播放第几个图片
   
    browser. photos = _localPicMsgArray ; // 数组中的是 MJPhoto 对象
    [browser show ];
    // 当键盘拉起的时候 , 需要关闭键盘 , 否则图片显示一半
    [ self doEndEditGesture ];
}
 
2)方法来返回第几个元素
 
- ( NSInteger )getPicUrl:( NSInteger )dd
{
    NSInteger c = 0 ;
    NSInteger d = 0 ;
    [ _localPicMsgArray removeAllObjects ];
    for ( int i= 0 ;i< self . dataSource . count ;++i) {
        id model = self . dataSource [i];
        NSInteger type = [ NSDictionary_Number_Object_ForKey (model, @"type" ) integerValue ];
        if (type == MESSAGE_TYPE_IMAGE ) {
            NSString * imageURL = [model objectForKey : @"imageURLpath" ]; // 远程 URL image
            NSString * imagePath = [model objectForKey : @"path" ]; // 本地 URL image
            MJPhoto *photo = [[ MJPhoto alloc ] init ];
            if ( IS_NS_STRING_EMPTY (imageURL)) {
                // 通过本地 URL 来查找 iamge 的方法
                for ( IDSPicSendModel *picModel in _localPicImageMsgArray ) {
                    if ([picModel. picPath isEqualToString :imagePath]) {
                        photo. image = picModel. picImage ;
                        NSLog ( @"%@" ,picModel. picPath );
                        break ;
                    }
                }
            }
            else {
                // 取远程 URL 方法
                photo. url = [ NSURL URLWithString :imageURL];
            }
            [ _localPicMsgArray cl_addObject :photo];
            if (i == dd) {
                c = d;
            }
            ++d;
        }
    }
    // 返回的是第几个图片元素
    return c;
}
 
 

转载于:https://www.cnblogs.com/firstrate/p/7489500.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值