uiwebview调整方向为横向后未调整大小

CodeLion

我正在编写一个iPhone应用程序,其中有一个UIWebView使用响应式设计加载网站的应用程序

我遇到的问题是将设备旋转到横向时:UIWebView旋转但其宽度保持与纵向模式相同。

我花了最后5个小时在整个网络上搜索,发现了一些我曾经使用过但没有成功的解决方案...

在我使用的html页面中

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

我尝试使用

<meta name="viewport" content="width=device-width" />

没什么改变,在我的代码中,我正在实现以下函数来处理旋转,但是它什么也没做

- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation
{
    [self.myWebView stringByEvaluatingJavaScriptFromString:
    [NSString stringWithFormat:
    @"document.querySelector('meta[name=viewport]').setAttribute('content', 'width=%d;', false); ",
    (int)self.myWebView.frame.size.width]];

    NSLog(@"orientation width: %d", (int)self.myWebView.frame.size.width);

}

我还选中了“按比例缩放页面”复选框,

(使用xcode 5,以及iphone4s和ios7)

斯科蒂

尝试在UIWebView上设置约束。当视图旋转时,空间约束应自动调整。

在情节提要中,找到右下角的菜单图标。选择自动布局图标(看起来像平局战士),然后选择“添加缺少的约束”或“重置为建议的约束”。在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章