我正在编写一个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)