【问题标题】:meta viewport tag doesn't seem to work in iOS UIWebView元视口标签似乎在 iOS UIWebView 中不起作用
【发布时间】:2015-10-13 13:20:26
【问题描述】:

为什么以下操作不起作用?目的是让div 具有 iphone 屏幕宽度的 1/2。它在桌面浏览器(例如 OSX Safari 和 Chrome)中按预期工作。

index.html:

<html>
<head>        
    <meta name="viewport" content="width=device-width,initial-scale=1" />  
</head>
<body>
<br><br><br> 
    <div style="background-color: red; width: 50%">hello iphone</div>
</body></html>

iOS 代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
    [_webView loadRequest:[NSURLRequest requestWithURL:url]];   
}

iphone模拟器:

【问题讨论】:

    标签: ios css uiwebview viewport meta


    【解决方案1】:

    xcode 7.0.1 + iOS9 中好像有meta viewportbugs;但是,建议的解决方法,例如 initial-scale=1.0001shrink-to-fit=no 对我不起作用。我试过模拟器和物理设备。

    这是迄今为止唯一有效的解决方案:

    <html>
        <body>
            <br><br><br>
            <div id="red-div" style="background-color: red;">hello iphone</div>
    
            <script>
                document.getElementById('red-div').style.width = screen.width/2 + 'px';
            </script>
    
        </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2017-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-25
      • 2016-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多