javascript - CATransition 在所需 View 之外显示动画

标签 javascript iphone ios objective-c uiwebview

我正在使用 CATranstion 动画在 UIWebView 中的多个 HTML 页面之间移动。

[WebView loadHTMLString:htmlPage baseURL:nil];
            CATransition *animation = [CATransition animation];
            [animation setType:kCATransitionPush];
            [animation setSubtype:kCATransitionFromLeft];
            [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
            [animation setSpeed:0.3];
            [[WebView layer] addAnimation:animation forKey:nil];
            [UIView commitAnimations];

Web View 不会显示在 iOS 设备屏幕的整体中,而是显示在屏幕的中间。问题是当执行转换时,文本显示在 web View 之外,我想要的是动画不会超出 web View 。 你能帮忙吗?

最佳答案

这就是 CATransition 的工作方式。

我建议您将 UIWebView 添加为某个容器 View 的 subview ,并为容器 View 设置 clipsToBounds = YES。它应该会像您想要的那样工作。

尝试这样的事情:

UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(60, 60, 200, 200)];
containerView.clipsToBounds = YES;
[self.view addSubview:containerView];

_webView = [[UIWebView alloc] initWithFrame:containerView.bounds];
_webView.backgroundColor = [UIColor redColor];
[containerView addSubview:_webView];

你的转换代码没问题,这应该做你想做的

对正在发生的事情的简单解释:Transition 在动画之前和之后制作层的“位图屏幕截图”。然后就制作动画。在您的情况下,它获得 2 个位图,将新位图放在旧位图的左侧,然后将旧位图“推”到右侧。

关于javascript - CATransition 在所需 View 之外显示动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16561731/

相关文章:

ios - 如何从 Swift 中的另一个 View Controller 更改标签的导出?

android - react native ffmpeg : Native module cannot be null (ios) and null is not an object (evaluating 'RNFFmpegModule.enableLogEvents' ) (android)

php - JavaScript 函数参数错误

javascript - 如何从没有 JQuery 的元素的 sibling 中删除类?

iphone - 当应用程序处于后台时运行 CLLocation

iphone - iPhone 应用程序中的 Google map 导航和方向

javascript - 将事件从 <body> 标记移动到脚本的正确方法

javascript - 返回多个组件会导致 libART 错误

iphone - UIDatePicker,根据今天的日期设置最大和最小日期

ios - TableView 不重新加载