0
我已經加載了幾個圖像到一個表視圖。圖像已被調整大小,我希望當用戶點擊圖像視圖時,它會彈出一個顯示原始圖像大小的視圖,並且當用戶再次單擊任何地方時,視圖消失並返回到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;
}