iOS编程如何在用户点击ImageView时全屏显示图像

标签 ios objective-c uiimageview

我想在用户点击时全屏显示图像。 谁能帮帮我吗? 我的 ImageView 在 TableViewCell 中。 这是我尝试过的:


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ImageListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    cell.propertyImageView.frame = [UIScreen mainScreen].bounds;
    cell.propertyImageView.image = [imageList objectAtIndex:indexPath.row];
}

最佳答案

这样很简单:

-(void)removeImage {

    UIImageView *imgView = (UIImageView*)[self.view viewWithTag:100];
    [imgView removeFromSuperview];
}

-(void)addImageViewWithImage:(UIImage*)image {

    UIImageView *imgView = [[UIImageView alloc] initWithFrame:self.view.frame];
    imgView.contentMode = UIViewContentModeScaleAspectFit;
    imgView.backgroundColor = [UIColor blackColor];
    imgView.image = image;
    imgView.tag = 100;
    UITapGestureRecognizer *dismissTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeImage)];
    dismissTap.numberOfTapsRequired = 1;
    [imgView addGestureRecognizer:dismissTap];
    [self.view addSubview:imgView];
}

像这样从你的表委托(delegate)中调用:

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

   [self addImageViewWithImage:[imageList objectAtIndex:indexPath.row]];
    }

关于iOS编程如何在用户点击ImageView时全屏显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42151885/

相关文章:

ios - 当 switch case 的默认 block 只有 id 调试行时,我的程序会在生产中崩溃吗

objective-c - 必须至少存在以下架构之一 : armv7 (-19033) Unable to validate your application. - (null)

ios - 是否可以使用 PDF 远程数据初始化 UIImage?

iphone - IOS7中的图像背景问题

ios - UIImageView.highlighted 不工作

ios - iOS 7 API不适用于带有iOS 7 SDK的iOS 6

objective-c - 意外的 NSAutoresizingMaskLayoutConstraint 从 Nib 添加 UIView 到自动布局 Storyboard场景

ios - OutputStream hasSpaceAvailable 永远不会变成 'true'

ios - 在 const NSString *const[] 中查找 NSString

ios - 在swift 5中获取目录中的文件名