【发布时间】:2013-10-04 08:59:36
【问题描述】:
我正在编写一个 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)
【问题讨论】:
标签: objective-c uiwebview xcode5 orientation landscape