UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(20, 10, Screen_width-40, 180)];
// 将base64字符串转为NSData
NSData *decodeData = [[NSData alloc]initWithBase64EncodedString:[orderInfoDic objectForKey:@"IMAGEURL"] options:(NSDataBase64DecodingIgnoreUnknownCharacters)];
// 将NSData转为UIImage
UIImage *decodedImage = [UIImage imageWithData: decodeData];
imageView.userInteractionEnabled = YES;
[imageView setImage:decodedImage];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showZoomImageView:)];
tapGesture.numberOfTapsRequired=1;
[imageView addGestureRecognizer:tapGesture];
[cell.contentView addSubview:imageView];
return cell;
//放大缩小图片
-(void)showZoomImageView:(UITapGestureRecognizer *)tap
{
if (![(UIImageView *)tap.view image]) {
return;
}
UIView *bgView = [[UIView alloc] init];
bgView.frame = [UIScreen mainScreen].bounds;
bgView.backgroundColor = [UIColor blackColor];
[[[UIApplication sharedApplication] keyWindow] addSubview:bgView];
UITapGestureRecognizer *tapBgView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBgView:)];
[bgView addGestureRecognizer:tapBgView];
//必不可少的一步,如果直接把点击获取的imageView拿来玩的话,返回的时候,原图片就完蛋了
UIImageView *tempImageView = (UIImageView*)tap.view;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:tempImageView.frame];
imageView.image = tempImageView.image;
[bgView addSubview:imageView];
[UIView animateWithDuration:0.5 animations:^{
CGRect frame = imageView.frame;
frame.size.width = bgView.frame.size.width;
frame.size.height = frame.size.width * (imageView.image.size.height / imageView.image.size.width);
frame.origin.x = 0;
frame.origin.y = (bgView.frame.size.height - frame.size.height) * 0.5;
imageView.frame = frame;
}];
}
-(void)tapBgView:(UITapGestureRecognizer *)tapBgRecognizer
{
[tapBgRecognizer.view removeFromSuperview];
}