图片查看器MJPhotoBrowser


MJPhotoBrowser实现了图片浏览和查看功能,我使用的只是查看。

#import "MJPhoto.h"

#import "MJPhotoBrowser.h"

UIImageView *imageView;

NSMutableArray *photos;


photos = [NSMutableArray arrayWithCapacity:1];
[self addImage:[UIImage imageNamed:@"ico_my.png"]];


-(void)addImage:(UIImage *)image
{
    [photos addObject:image];
    imageView = [[UIImageView alloc]initWithImage:image];
    imageView.frame = CGRectMake(20, 60, 30, 60);
//    imageView.contentMode = UIViewContentModeScaleToFill;
    imageView.userInteractionEnabled = YES;
    [imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(photoTap:)]];
    [self.view addSubview:imageView];
}

//点击预览图片
- (void)photoTap:(UITapGestureRecognizer *)recognizer
{
    //1.创建图片浏览器
    NSMutableArray *kjphotos = [NSMutableArray array];
    MJPhotoBrowser *brower = [[MJPhotoBrowser alloc] init];
    
    //2.告诉图片浏览器显示所有的图片
    for (int i = 0 ; i < photos.count; i++) {
        //传递数据给浏览器
        MJPhoto *photo = [[MJPhoto alloc] init];
        photo.image = photos[i];
        photo.srcImageView = imageView; //设置来源哪一个UIImageView
        [kjphotos addObject:photo];
    }
    brower.photos = kjphotos;
    
    //3.设置默认显示的图片索引
    brower.currentPhotoIndex = recognizer.view.tag;
    
    //4.显示浏览器
    [brower show];
}


你可能感兴趣的:(iOS)