Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
元视口标记没有';在iOS UIWebView中似乎不起作用_Ios_Css_Uiwebview_Viewport_Meta - Fatal编程技术网

元视口标记没有';在iOS UIWebView中似乎不起作用

元视口标记没有';在iOS UIWebView中似乎不起作用,ios,css,uiwebview,viewport,meta,Ios,Css,Uiwebview,Viewport,Meta,为什么下面的方法不起作用?其目的是使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>&

为什么下面的方法不起作用?其目的是使
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>
- (void)viewDidLoad {
    [super viewDidLoad];
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
    [_webView loadRequest:[NSURLRequest requestWithURL:url]];   
}
iphone模拟器:

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

在xcode 7.0.1+iOS9中似乎有
元视口
;然而,建议的变通方法,如
初始比例=1.0001
收缩到适合=否
对我来说并不奏效。我试过使用模拟器和物理设备

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

<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>




你好,iphone document.getElementById('red-div')。style.width=screen.width/2+'px';