【问题标题】:Expand UIImageView to full screen from within UITableViewCell从 UITableViewCell 将 UIImageView 扩展到全屏
【发布时间】:2014-01-20 19:47:25
【问题描述】:

我在UITableViewCell 中有一个UIImageView 并希望将其扩展为全屏,我已经设置了我的UIGestureRecognizer 并使用此代码来扩展框架:

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

但是UIImageView 只会扩展以填充UITableViewCell 而不会填充全屏。

任何帮助将不胜感激。

【问题讨论】:

  • 不要使用相同的 imageView,因为单元格 clipsToBounds 设置为 Yes,因此单元格边界外的视图将不可见。检查我的答案以实现您的功能。

标签: ios uitableview uiimageview


【解决方案1】:

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

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

你需要在imageView中添加gestureRecognizer,并将选择器设置为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;
}

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2015-04-19
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 2019-04-23
      • 2014-09-07
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      相关资源
      最近更新 更多