0
여러 이미지를 테이블 뷰에로드했습니다. 이미지의 크기가 조정되었으므로 사용자가 이미지 뷰를 탭하면 원본 이미지 크기를 보여주는 뷰가 팝업되고 사용자가 아무 곳이나 클릭하면 뷰가 사라지고 다시 뷰 뷰로 되돌아 가도록합니다. 다음과 같이 이미지를로드하는 코드 :이미지 뷰 팝업을 클릭하면 원본 이미지를 보여주는 뷰가 나타납니다.
- (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;
}