gpt4 book ai didi

ios - UIView 动画将 View 重置为原始矩形

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:50:24 25 4
gpt4 key购买 nike

我正在尝试在点击链接时从右边框将 UIWebView 动画化到屏幕上。为此,我使用了两个 UIView。一个称为 onScreenWebView,另一个称为 offScreenWebView。我的想法是,我可以将 offscreenWebView 从右侧动画化到屏幕上,并将 onScreenWebView 动画化到离开屏幕到左侧。然后交换 View (因此屏幕上的 View 变为 onScreenWebView,反之亦然)但我的动画有问题。我必须指出,它在第一次使用时效果很好。之后,它根本无法正常工作。

View 是这样对齐的

      __________ __________
| | | |
| on | | off |
| screen | | screen |
|________| |________|

这是动画代码:

offScreenWebView.hidden = true;

offScreenWebView.frame = self.frame;
[offScreenWebView offSetX:self.bounds.size.width + kOffsetPadding]; // move offscreen to the right
[self logWebRects:@"begin"];
offScreenWebView.hidden = false;
[self bringSubviewToFront:offScreenWebView];

[UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationCurveEaseInOut animations:^{
[self logWebRects:@"during 1"];
offScreenWebView.frame = self.frame;
onScreenWebView.frame = CGRectMake(-(self.bounds.size.width + kOffsetPadding), 0, onScreenWebView.bounds.size.width, onScreenWebView.bounds.size.height);
[self logWebRects:@"during 2"];
}completion:^(BOOL finished) {
[self logWebRects:@"finished b4 swap"];
[self swapWebViews];
[self logWebRects:@"finished -- done"];
}];

这是我的 logWebRects 方法的输出(只是每个 View 的来源)

Navigation Type ::      Link Clicked
Rect of self frame :: {{0, 0}, {320, 460}}

99 -- Point of offscreen origin begin :: {335, 0}
0 -- Point of onscreen origin begin :: {0, 0}
99 -- Point of offscreen origin during 1 :: {335, 0}
0 -- Point of onscreen origin during 1 :: {0, 0}
99 -- Point of offscreen origin during 2 :: {0, 0}
0 -- Point of onscreen origin during 2 :: {-335, 0}
Navigation Type :: Other
99 -- Point of offscreen origin finished b4 swap :: {0, 0}
0 -- Point of onscreen origin finished b4 swap :: {-335, 0}
0 -- Point of offscreen origin finished -- done :: {-335, 0}
99 -- Point of onscreen origin finished -- done :: {0, 0}


Navigation Type :: Link Clicked
Rect of self frame :: {{0, 0}, {320, 460}}

0 -- Point of offscreen origin begin :: {335, 0}
99 -- Point of onscreen origin begin :: {0, 0}
0 -- Point of offscreen origin during 1 :: {335, 0}
99 -- Point of onscreen origin during 1 :: {0, 0}
0 -- Point of offscreen origin during 2 :: {0, 0}
99 -- Point of onscreen origin during 2 :: {-335, 0}
Navigation Type :: Other
0 -- Point of offscreen origin finished b4 swap :: {335, 0}
99 -- Point of onscreen origin finished b4 swap :: {0, 0}
99 -- Point of offscreen origin finished -- done :: {0, 0}
0 -- Point of onscreen origin finished -- done :: {335, 0}

这些日志来自初始运行。然后也是第二轮。您会注意到,无论出于何种原因,动画 block 都会在完成 block 之前重置每个 Web View 的框架。

我应该注意,我使用经典的临时变量交换来交换 Web View 。此外,它们是兄弟 View 。

最佳答案

我知道这有点老了,但我遇到了同样的问题,这是我找到的唯一关于它的帖子。

问题是 bringSubviewToFront 执行隐式动画(我猜)阻止动画 block 分配正确的帧。

我通过禁用隐式动画解决了这个问题。尝试使用这段代码代替普通的 bringSubviewToFront。

[CATransaction begin];
[CATransaction setDisabledActions:YES];
[self bringSubviewToFront:offScreenWebView];
[CATransaction commit];

关于ios - UIView 动画将 View 重置为原始矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11838209/

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