【问题标题】:How to resize webview correctly in landscape mode in iPhone?如何在 iPhone 的横向模式下正确调整 webview 的大小?
【发布时间】:2010-09-25 08:29:11
【问题描述】:

我添加了一个导航栏、一个 web 视图和一个工具栏(从上到下)作为我的 viewcontroller 视图的子视图。我希望导航栏和工具栏的高度在横向上缩小一点,所以我使用 autoresizingmask 来使高度灵活。 (UIViewAutoresizingFlexibleHeight 会使导航栏和工具栏的高度从 44 缩小到 30 左右):

webNavBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;
webToolBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

现在我发现当我将设备旋转到横向模式时,webview的顶部和底部会出现两个空白白条(每个空白条的高度为44-30)。导航栏和工具栏似乎在正确的位置。有没有办法调整 webview 的大小并填补空白?

【问题讨论】:

    标签: iphone uiwebview resize landscape


    【解决方案1】:

    您确定为 web 视图正确设置了自动调整边距吗?总能做到:

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

    不知道这是否可行,但值得一试。

    【讨论】:

    • 感谢您的回答,但网页视图不是全屏视图。无论如何,你给我一个想法,我可以重置它的框架以获得正确的大小。
    • 确保你也调用了super方法,以防你在超类中做任何事情。
    【解决方案2】:

    检查此链接。 UIWebView not re-sizing after changing orientation to landscape

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

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

    【讨论】:

    • 确保你也调用了super方法,以防你在超类中做任何事情。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-20
    • 2011-09-05
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多