标签:
一个比较完整的图片浏览器,高仿了新浪微博的图片浏览效果,功能包括:下载浏览互联网图片,点击缩略图全屏显示图片、当加载较大图片时会出现圆形进度条,滑动浏览所有图片、保存图片到本地相册、GIF图片播放等。而且仅需几行代码就能添加图片浏览器功能。
项目地址:http://code4app.com/ios/快速集成图片浏览器/525e06116803fa7b0a000001
使用:
for (int i = 0; i<3; i++) {
UIImageView *img = [[UIImageView alloc]init];
img.tag = i;
//单击 添加手势
UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapPhoto:)];
[singleTapGestureRecognizer setNumberOfTapsRequired:1];
[img addGestureRecognizer:singleTapGestureRecognizer];
//这一行很重要 imageview默认不能进行交互
img.userInteractionEnabled = YES;
[img setContentMode:UIViewContentModeScaleAspectFill];
img.clipsToBounds = YES;
[CDUtils displayIconImageWithUrl:model.photos[i] imageView:img];
img.frame = CGRectMake((([UIScreen mainScreen].bounds.size.width-2)/3+1)*i, 0, ([UIScreen mainScreen].bounds.size.width-2)/3,([UIScreen mainScreen].bounds.size.width-2)/3);
[self.imagePicView addSubview:img];
}
/** * 监听图片的点击 */ - (void)tapPhoto:(UITapGestureRecognizer *)recognizer { //1.创建图片浏览器 MJPhotoBrowser *brower = [[MJPhotoBrowser alloc] init]; //2.告诉图片浏览器显示所有的图片 NSMutableArray *photos = [NSMutableArray array]; for (int i = 0 ; i < self.picAry.count; i++) { //传递数据给浏览器 MJPhoto *photo = [[MJPhoto alloc] init]; photo.url = [NSURL URLWithString:self.picAry[i]]; NSLog(@"%@",photo.url); photo.srcImageView = (UIImageView *)recognizer.view; //设置来源哪一个UIImageView [photos addObject:photo]; } brower.photos = photos; //3.设置默认显示的图片索引 brower.currentPhotoIndex = recognizer.view.tag; //4.显示浏览器 [brower show]; }
要包含这两个头文件:
#import "MJPhoto.h"
#import "MJPhotoBrowser.h"
快速集成图片浏览器快速集成图片浏览器->MJPhotoBrowser的使用
标签:
原文地址:http://www.cnblogs.com/gaoxiaoniu/p/5316602.html