旋转后UIWebView内容未调整为新帧 [英] UIWebView content not adjusted to new frame after rotation
问题描述
我有一个电子邮件应用程序,
在 UISplitViewController $中显示
UIWebView
中的内容c $ c>。
一切正常,直到我旋转设备,当已经在 UIWebView
中放大/缩小时。
旋转设备时,我调整了 UIWebView
的框架
I have an e-mail application,
which shows the content in an UIWebView
inside an UISplitViewController
.
Everything works fine until i rotate the device, when already zoomed in/out in the UIWebView
.
When rotating the device, i adjust the frame of the UIWebView
in
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
问题是,当我放大时/ out在 UIWebView
中,然后旋转设备。
内容未调整为新的框架,导致灰色/黑色边框在内容中,或内容可以水平滚动。
The problem is, when i zoomed in/out in the UIWebView
and then rotate the device.
The content isn't resized to it's new frame, which leads to a gray/black border in the content, or the content can be scrolled horizontal.
地址信息:
UIWebView
是可以滚动的 UIScrollView
上的子视图。
当 UIWebView
完全可见 UIScrollView的
已禁用,并且可以滚动 scrollEnabled
UIWebView
。
Addional information:
The UIWebView
is a subview on a UIScrollView
which can be scrolled.
When the UIWebView
is totally visible the scrollEnabled
of the UIScrollView
is disabled and the UIWebView
can be scrolled.
上图显示选择电子邮件时的横向 UIWebView
。
这是两种情况下旋转前的状态。
[旋转前未缩放] 上图显示 UIWebView
正在正确调整内容的大小新框架。
[旋转前缩放] 上图显示了 UIWebView
放大横向然后旋转到肖像
- >内容不正确显示
UIWebView.scrollView $ c的信息$ c> in
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
:
< _UIWebViewScrollView :0xb1322a0; frame =(0 0; 768 960); clipsToBounds = YES; autoresize = H; gestureRecognizers =< NSArray:0xb1321d0> ;; layer =< CALayer:0xb132270> ;; contentOffset:{0,0}>
帧是正确的!
Above picture shows the UIWebView
in landscape when selecting an email.
This is the state before rotating in both cases.
[Not zoomed before rotating]Above picture shows that the UIWebView
is correctly resizing the content to it's new frame.
[Zoomed before rotating]Above picture shows the UIWebView
after zooming in landscape and then rotating to portrait
-> content isn't correctly shown
Information of the UIWebView.scrollView
in
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
:
<_UIWebViewScrollView: 0xb1322a0; frame = (0 0; 768 960); clipsToBounds = YES; autoresize = H; gestureRecognizers = <NSArray: 0xb1321d0>; layer = <CALayer: 0xb132270>; contentOffset: {0, 0}>
frame is correct!
编辑:解决方案!!
i设法通过在旋转设备后更新视口宽度来解决它
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];
Solution!!
i managed to solve it by updating the viewport width after rotating the device
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];
推荐答案
我设法通过更新来解决它旋转设备后的视口宽度
i managed to solve it by updating the viewport width after rotating the device
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内容未调整为新帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!