如何在 iPhone 的横向模式下正确调整 webview 的大小?
我添加一个导航栏、一个网络视图和一个工具栏(从上到下)作为视图控制器视图的子视图。我希望导航栏和工具栏的高度在横向方向上稍微缩小一些,因此我使用 autoresizingmask 来使高度灵活。 (UIViewAutoresizingFlexibleHeight会让navigationbar和toolbar的高度从44缩小到30左右):
webNavBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;
webToolBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
现在我发现当我将设备旋转到横向模式时,webview的顶部和底部会出现两个空白的白色条(每个空白条的高度为44-30)。导航栏和工具栏似乎位于正确的位置。有什么方法可以调整网络视图的大小并填补空白吗?
I add a navigationbar, a webview and a toolbar(from top to bottom) as subviews of my viewcontroller's view. I want the navigationbar and toolbar's height shrink a little in landscape orientation so I use autoresizingmask to make the height flexible. (UIViewAutoresizingFlexibleHeight will make navigationbar and toolbar's height shrink from 44 to around 30):
webNavBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;
webToolBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Now I found that when I rotate the device to landscape mode, there will be two blank white bars on the top and bottom of the webview(each blank bar's height is 44-30). Navigationbar and toolbar appear to be in the correct position. Is there any way to resize the webview and fill the gaps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定 Web 视图的自动调整边距设置正确吗?总是可以做:
不知道这是否有效,但值得一试。
Are you sure the Autoresizing margins are set correctly for the webview? could always do:
No idea if that will work but worth a shot.
检查此链接。
UIWebView
在将方向更改为景观这对我有用:-
将以下代码添加到具有 webView 的控制器中:-
Check this link.
UIWebView
not re-sizing after changing orientation to landscapeThis worked for me: -
Add the following code to the controller which has the webView: -