从UITableViewCell内将UIImageView扩展为全屏

时间:2014-01-20 19:47:25

标签: ios uitableview uiimageview

我在UIImageView中有一个UITableViewCell,想要展开它以填满整个屏幕,我已经设置了UIGestureRecognizer并使用此代码扩展框架:

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

但是UIImageView只会展开以填充UITableViewCell并且不会填满整个屏幕。

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:9)

  

cells clipsToBounds设置为Yes,因此在单元格边界外的视图将是   不可见

以下方法将帮助您将单元格中的图像设置为全屏,然后将其恢复到同一位置。

您需要将gestureRecognizer添加到imageView并将选择器设置为cellImageTapped

声明UIImageView * temptumb,fullview;作为实例变量。

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

答案 1 :(得分:0)

UITableViewCell仅在重新加载数据 reloadRowsAtIndexPaths:withRowAnimation 时展开 否则它不会改变表中的大小,只需在self.view中添加UIImageView并隐藏图像视图,当关闭全视图时隐藏图像视图后点击单元格图像以更改图像视图图像