我已经将几个图像加载到表视图中。图像已调整大小,我希望当用户点击 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;
}