ios - 如何从表格 View 中正确放大图像

标签 ios objective-c uitableview uiimage

我正在使用以下代码从表格 View 中缩放/放大图像。我希望它放大到全屏。当前的问题是,当它放大时,它仅在表格单元格内放大(因此部分隐藏在下一个表格单元格下方)而不是完整 View 。

    -(void)zoomPhotoMethod :(id) sender
{
    UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) sender;
    NSLog(@"Tag = %d", gesture.view.tag);

    userSubmittedImageView = (UIImageView *)gesture.view;

    if (!isFullScreen) {
        [UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
            //save previous frame
            prevFrame = userSubmittedImageView.frame;

            UIView *popupImageViewForTableCell = [[UIView alloc] initWithFrame: CGRectMake ( 0, 0, 320, 500)];

            [userSubmittedImageView setFrame:[popupImageViewForTableCell bounds]];


        }completion:^(BOOL finished){
            isFullScreen = TRUE;
        }];
        return;
    }
    else{
        [UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
            [userSubmittedImageView setFrame:prevFrame];
        }completion:^(BOOL finished){
            isFullScreen = FALSE;;
        }];
        return;
    }


}

更新代码:
   -(void)zoomPhotoMethod :(id) sender
{
    UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) sender;
    NSLog(@"Tag = %d", gesture.view.tag);

    userSubmittedImageView = (UIImageView *)gesture.view;

    if (!isFullScreen) {
        [UIView animateWithDuration:0.3 delay:0 options:0 animations:^{
            //save previous frame
            prevFrame = userSubmittedImageView.frame;


            newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)];

            [self.view addSubview:newView];

            UIView *popupImageViewForTableCell = [[UIView alloc] initWithFrame: CGRectMake ( 0, 0, 320, 500)];

            [userSubmittedImageView setFrame:[popupImageViewForTableCell bounds]];

            [newView addSubview:userSubmittedImageView];

            [userSubmittedImageView setFrame:[newView bounds]];

        }completion:^(BOOL finished){
            isFullScreen = TRUE;
        }];
        return;
    }
    else{
        [UIView animateWithDuration:0.3 delay:0 options:0 animations:^{

            [userSubmittedImageView setFrame:prevFrame];


            [newView setFrame:prevFrame];

        }completion:^(BOOL finished){
            isFullScreen = FALSE;;
        }];
        return;
    }


}

最佳答案

发生的事情是您仍然是 tableview 单元格的 subview ,因此它不能在不被剪裁的情况下超出这些范围。

要做你想做的事,你必须:

  • 在表格 View 之外创建一个新的 UIImageView(将其添加为表格 View 之外的 subview )。
  • 将 ImageView 中的图像设置为与表格 View 单元格中相同的图像。
  • 以与 tableview 单元格图像相同的大小和位置启动它。
  • 将其动画到您想要的位置。
  • 当需要删除它时,将其移回原始的 tableview 单元格图像。
  • 丢弃 ImageView 。
  • 关于ios - 如何从表格 View 中正确放大图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19592239/

    相关文章:

    ios - NSError 版本 : message sent to deallocated instance

    ios - 将数据传递到详细信息 View 、实际数据或引用 ID

    ios - 触摸单元格时更改 UITableViewCell 的附件类型

    ios - 如何使用 AVfoundation (swift3) 将照片放在 imageView 上

    ios 通用应用程序只显示 3.5 英寸屏幕而不是 4 英寸屏幕

    iphone - 如何声明此应用程序的设备功能?

    objective-c - 如何解决 Objective-C 中的 "NSInternalInconsistencyException"错误?

    ios - 单击 TableViewCell 后使用参数运行方法

    ios - 手动将坐标转换为点到 View

    ios - react native 运行ios : The bundle identifier of the application could not be determined