Expand UIImageView to full screen from within UITa

2019-01-29 04:44发布

I have a UIImageView within a UITableViewCell and want to expand it to fill the full screen, I have setup my UIGestureRecognizer and am using this code to expand the frame:

[UIView animateWithDuration:1.0 animations:^{
        [self.ImageView setFrame:[[UIScreen mainScreen] applicationFrame]];
}];

However the UIImageView will only expand to fill the UITableViewCell and does not fill the full screen.

Any help would be much appreciated.

2条回答
做自己的国王
2楼-- · 2019-01-29 05:29

cells clipsToBounds is set to Yes, so view outside the cell bound will not visible

Following method will help u to get image in cell to full Screen then get it back to same place.

You need to add gestureRecognizer to imageView and set selector as cellImageTapped

Declare UIImageView *temptumb,fullview; as instance variable.

- (void)cellImageTapped:(UIGestureRecognizer *)gestureRecognizer {
    NSLog(@"%@", [gestureRecognizer view]);
    //create new image
    temptumb=(UIImageView *)gestureRecognizer.view;
    //temptumb=thumbnail;
    fullview=[[UIImageView alloc]init];
      [fullview setContentMode:UIViewContentModeScaleAspectFit];
    fullview.image = [(UIImageView *)gestureRecognizer.view image];
        CGRect point=[self.view convertRect:gestureRecognizer.view.bounds fromView:gestureRecognizer.view];
    [fullview setFrame:point];

    [self.view addSubview:fullview];

    [UIView animateWithDuration:0.5
                     animations:^{
                         [fullview setFrame:CGRectMake(0,
                                                       0,
                                                       self.view.bounds.size.width,
                                                       self.view.bounds.size.height)];
                     }];
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fullimagetapped:)];
    singleTap.numberOfTapsRequired = 1;
    singleTap.numberOfTouchesRequired = 1;
    [fullview addGestureRecognizer:singleTap];
    [fullview setUserInteractionEnabled:YES];
}
- (void)fullimagetapped:(UIGestureRecognizer *)gestureRecognizer {

    CGRect point=[self.view convertRect:temptumb.bounds fromView:temptumb];

    gestureRecognizer.view.backgroundColor=[UIColor clearColor];
    [UIView animateWithDuration:0.5
                     animations:^{
                         [(UIImageView *)gestureRecognizer.view setFrame:point];
                     }];
    [self performSelector:@selector(animationDone:) withObject:[gestureRecognizer view] afterDelay:0.4];

}

-(void)animationDone:(UIView  *)view
{
    [fullview removeFromSuperview];
    fullview=nil;
}
查看更多
一夜七次
3楼-- · 2019-01-29 05:31

UITableViewCell only expand when reloaddata or reloadRowsAtIndexPaths:withRowAnimation otherwise it not change size in table,Simply you add UIImageView in self.view and hide image view,when tap the cell image to change image view image after hide image view when close full view

查看更多
登录 后发表回答