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

Posted

技术标签:

【中文标题】iOS编程如何在用户点击ImageView时全屏显示图像【英文标题】:iOS Programming How to show image fullscreen when user tap on ImageView 【发布时间】:2017-02-10 05:05:33 【问题描述】:

当用户点击它时,我想全屏显示图像。 任何人都可以帮助我吗? 我的 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];

【问题讨论】:

检查这个答案:***.com/a/21260074/4831524 您的代码不包含显示全屏图像的代码。你想如何显示全屏图像?表视图之上的层,还是新的视图控制器? 是的,在 tableView 的顶层。谢谢!你能帮帮我吗? 【参考方案1】:

这很简单:

-(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];

像这样从您的表委托中调用:

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

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

【讨论】:

以上是关于iOS编程如何在用户点击ImageView时全屏显示图像的主要内容,如果未能解决你的问题,请参考以下文章