一、使用方法:
#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;
}