如何在 iPhone 的横向模式下正确调整 webview 的大小?

发布于 2024-09-25 12:07:50 字数 680 浏览 8 评论 0原文

我添加一个导航栏、一个网络视图和一个工具栏(从上到下)作为视图控制器视图的子视图。我希望导航栏和工具栏的高度在横向方向上稍微缩小一些,因此我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

英雄似剑 2024-10-02 12:07:50

您确定 Web 视图的自动调整边距设置正确吗?总是可以做:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
   webView.frame = self.view.frame;
}

不知道这是否有效,但值得一试。

Are you sure the Autoresizing margins are set correctly for the webview? could always do:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
   webView.frame = self.view.frame;
}

No idea if that will work but worth a shot.

旧伤还要旧人安 2024-10-02 12:07:50

检查此链接。
UIWebView 在将方向更改为景观

这对我有用:-
将以下代码添加到具有 webView 的控制器中:-

 (void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration  
 {
     [self.myWebView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
 }

Check this link.
UIWebView not re-sizing after changing orientation to landscape

This worked for me: -
Add the following code to the controller which has the webView: -

 (void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration  
 {
     [self.myWebView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文