单击图像视图弹出显示原始图像的视图
Posted
技术标签:
【中文标题】单击图像视图弹出显示原始图像的视图【英文标题】:Click a imageview popup a view showing the original image 【发布时间】:2013-04-18 06:24:43 【问题描述】:我已将多个图像加载到表视图中。图像已调整大小,我希望当用户点击 imageview 时,它会弹出一个显示原始图像大小的视图,当用户再次单击任意位置时,视图会消失并返回 tableview。加载图像的代码如下:
- (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *cellIdentifier = @"Cell";
SearchCell *cell = (SearchCell *)[atableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell)
cell = [[[NSBundle mainBundle] loadNibNamed:@"SearchCell" owner:self options:nil] objectAtIndex:0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.name.text = [[self.brands objectAtIndex:indexPath.row] objectForKey:@"name"];
__weak SearchCell *weakCell = cell;
[cell.leftImageView setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://s-57130.gotocdn.com/%@", [[self.brands objectAtIndex:indexPath.row] objectForKey:@"pic"]]]] placeholderImage:[UIImage imageNamed:@"app_icon.png"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image)
CGFloat imageHeight = image.size.height;
CGFloat imageWidth = image.size.width;
CGSize targetSize = CGSizeMake(70, 70);
CGSize newSize = targetSize;
CGFloat scaleFactor = targetSize.width / imageWidth;
newSize.height = imageHeight * scaleFactor;
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *small = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
weakCell.imageView.image = small;
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error)
];
return cell;
【问题讨论】:
【参考方案1】:无需手动调整图像大小。如果将imageView
contentMode
属性设置为UIViewContentModeScaleAspectFill
,它将自动缩放以适应图像视图的大小。
关于点击缩放,请查看UIImageViewModeScaleAspect。
【讨论】:
以上是关于单击图像视图弹出显示原始图像的视图的主要内容,如果未能解决你的问题,请参考以下文章