单击图像浏览弹出一个视图显示原始图像

问题描述:

我已经加载了几个图像到一个表视图。图像已被调整大小,我希望当用户点击图像视图时,它会弹出一个显示原始图像大小的视图,并且当用户再次单击任何地方时,视图消失并返回到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; 
} 

无需手动调整图像大小。如果将imageViewcontentMode属性设置为UIViewContentModeScaleAspectFill,它将自动缩放以适合图像视图的大小。

至于缩放水龙头,检查出UIImageViewModeScaleAspect