我正在使用 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/