• 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 = [[MJPhotoBrowseralloc] init];
       
        browser.currentPhotoIndex = [selfgetPicUrl:cell.indexPath.row];//获取播放第几个图片
       
        browser.photos = _localPicMsgArray;//数组中的是MJPhoto对象
        [browser show];
        //当键盘拉起的时候, 需要关闭键盘, 否则图片显示一半
        [selfdoEndEditGesture];
    }
     
    2)方法来返回第几个元素
     
    - (NSInteger)getPicUrl:(NSInteger)dd
    {
        NSInteger c = 0;
        NSInteger d = 0;
        [_localPicMsgArrayremoveAllObjects];
        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"];//远程URLimage
                NSString* imagePath = [model objectForKey:@"path"];//本地URLimage
                MJPhoto *photo = [[MJPhotoalloc] init];
                if (IS_NS_STRING_EMPTY(imageURL)) {
                    //通过本地URL来查找iamge的方法
                    for (IDSPicSendModel *picModel in_localPicImageMsgArray) {
                        if ([picModel.picPathisEqualToString:imagePath]) {
                            photo.image = picModel.picImage;
                            NSLog(@"%@",picModel.picPath);
                            break;
                        }
                    }
                }
                else {
                    //取远程URL方法
                    photo.url = [NSURLURLWithString:imageURL];
                }
                [_localPicMsgArraycl_addObject:photo];
                if (i == dd) {
                    c = d;
                }
                ++d;
            }
        }
        //返回的是第几个图片元素
        return c;
    }
     
     
  • 相关阅读:
    oracle 主键自动地址实现
    解构赋值
    那些朋友那些话系列
    那些朋友那些话
    白鹭记事
    该如何存在
    上海秋季HCC小记
    For the person you never see again
    寻城记
    2013年的国庆
  • 原文地址:https://www.cnblogs.com/firstrate/p/7489500.html
Copyright © 2020-2023  润新知