gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 17:54:54 25 4
gpt4 key购买 nike

我正在使用以下代码从表格 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/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com