【发布时间】:2014-03-16 10:16:53
【问题描述】:
我有一个电子邮件应用程序,
它在UISplitViewController 内显示UIWebView 中的内容。
一切正常,直到我旋转设备,当已经在UIWebView 中放大/缩小时。
旋转设备时,我调整了UIWebView in
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
问题是,当我放大/缩小 UIWebView 然后旋转设备时。
内容未根据新框架调整大小,这会导致内容出现灰/黑边框,或者内容可以水平滚动。
附加信息:
UIWebView 是 UIScrollView 上的子视图,可以滚动。
当UIWebView完全可见时,UIScrollView的scrollEnabled被禁用,UIWebView可以滚动。
上图显示了选择电子邮件时的UIWebViewin 横向。
这是两种情况下旋转前的状态。
[旋转前未缩放]上图显示UIWebView正在正确调整大小内容到它的新框架。
[旋转前缩放]上图显示了UIWebView在横向放大然后旋转到纵向后
-> 内容显示不正确UIWebView.scrollView的信息- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation:<_UIWebViewScrollView: 0xb1322a0; frame = (0 0; 768 960); clipsToBounds = YES; autoresize = H; gestureRecognizers = <NSArray: 0xb1321d0>; layer = <CALayer: 0xb132270>; contentOffset: {0, 0}>
框架是正确的!
编辑:解决方案!!
我设法通过在旋转设备后更新视口宽度来解决它CGFloat fll_width = self.view.frame.size.width;
NSString* adsl_javascript_string = [NSString stringWithFormat:@"var setViewPortScript = document.createElement('meta');\
setViewPortScript.setAttribute('name', 'viewport');\
setViewPortScript.setAttribute('content', 'width = %f');\
document.getElementsByTagName('head')[0].appendChild(setViewPortScript);", fll_width];
[adsc_webview stringByEvaluatingJavaScriptFromString:adsl_javascript_string];
【问题讨论】:
-
您知道
UIWebView是UIScrollView的子类,所以我只是想知道额外的UIScrollView的逻辑是什么,您所描述的一切都可以通过@987654346 来实现@,
标签: ios objective-c ipad uiwebview uiscrollview