小编Cod*_*ion的帖子

uiwebview在改变横向方向后没有调整大小

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

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

我花了最后5个小时在网上搜索,我找到了一些我用过但没有成功的解决方案......

在我正在使用的html页面中

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
Run Code Online (Sandbox Code Playgroud)

我试过用

<meta name="viewport" content="width=device-width" />
Run Code Online (Sandbox Code Playgroud)

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

- (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);

}
Run Code Online (Sandbox Code Playgroud)

我还检查了"缩放页面以适合"复选框,

(使用xcode 5,带有iphone4s和ios7)

landscape objective-c uiwebview orientation xcode5

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

landscape ×1

objective-c ×1

orientation ×1

uiwebview ×1

xcode5 ×1