title: How do I expand image to full view when being tapped in a UICollectionView?
body: <p>In my project I'm using a <code>UICollectionView</code> for displaying images and I'm also using <code>UIImageView</code> in <code>UICollectionViewCell</code>.
  All I want is when I tap on a image it should expand and show on fullscreen.
  For this I've created a new view takes a <code>UIImageView</code> on it and apply TapGesture on <code>UICollectionViewCells</code>.
  The expanded image open in the next view but isn't presented in the frame I give it.
  and also when i click on any pic it removed from the collection view. please tell me how to reload <code>UICollectionViewCells</code><a href="https://i.stack.imgur.com/KytCD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KytCD.png" alt="enter image description here"></a>
  Please suggest me how to put image on the prescribed frames.
  I'm sharing my code</p>
  
  <pre><code>- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  {
      UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
  
      imgview = (UIImageView *)[cell viewWithTag:100];
      imgview = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,160, 160)];
  
      imgview.image = [UIImage imageNamed:[imagearray objectAtIndex:indexPath.row]];
      //cell.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:[imagearray objectAtIndex:indexPath.row]]];
      [cell.contentView addSubview:imgview];
  
      UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(expandImage:)];
      tapped.numberOfTapsRequired = 1;
      [imgview setUserInteractionEnabled:YES];
      imgview.tag = indexPath.row;
      [imgview addGestureRecognizer:tapped];
  
      [cell.contentView addSubview:imgview];
  
      return cell;
  }
  
  -(void)expandImage:(UITapGestureRecognizer*)recogniser
  {
      UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 50, self.view.frame.size.width , self.view.frame.size.height)];
      view1.backgroundColor = [UIColor greenColor];
      [self.view addSubview:view1];
  
      UIButton *closeButton = [[UIButton alloc]initWithFrame:CGRectMake(310, 10, 50, 40)];
      [closeButton setTitle:@"Close" forState:UIControlStateNormal];
      [closeButton addTarget:self action:@selector(Closetab) forControlEvents:UIControlEventTouchUpInside];
      [view1 addSubview:closeButton];
  
      UIImageView *photoView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 70, self.view.frame.size.width, self.view.frame.size.height-200)];
      [photoView setBackgroundColor:[UIColor blueColor]];
      [view1 addSubview:photoView];
      photoView.accessibilityIdentifier = @"nature2.png";
  
      UIImageView *photoView1 = (UIImageView*)recogniser.view;
      photoView1.accessibilityIdentifier = @"nature2.png";
  
      //photoView.clipsToBounds = YES;
  
      // photoView.accessibilityIdentifier = @"apple1.png";
  
      photoView1.contentMode =  UIViewContentModeScaleAspectFill;
  
      //photoView1.clipsToBounds = YES;
      [view1 addSubview:photoView1];  
  }
  </code></pre>