当点击链接时,我正在尝试从右边框将 UIWebView 动画到屏幕上。为了做到这一点,我使用了两个 UIView。一个叫onScreenWebView,另一个叫offScreenWebView。这个想法是我可以将 offscreenWebView 从右侧设置到屏幕上,并将 onScreenWebView 设置到左侧的屏幕上。然后交换视图(因此屏幕上的视图变为 onScreenWebView,反之亦然)但我的动画有问题。我必须注意它第一次效果很好。在那之后,它根本无法正常工作。
视图是这样对齐的
__________ __________
| | | |
| 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 方法的输出(只是每个视图的来源)
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}
这些日志来自初始运行。然后也是第二轮。您会注意到,无论出于何种原因,动画块都会在完成块之前重置每个 Web 视图的帧。
我应该注意,我用经典的临时变量交换交换了 Web 视图。此外,它们是兄弟视图。