UIwebview媒体查询纵向

时间:2012-04-26 10:40:37

标签: html objective-c css ios orientation

我试图在webview中加载一些html,我希望将不同的CSS用于横向和纵向方向

这是我html的主要部分

NSMutableString *htmlString = [NSMutableString stringWithString:@"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"];

        [htmlString appendString:@"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" id=\"bp-doc\">"
         "<head>"
         "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>"
         "<meta name=\"viewport\" content=\"width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;\" />" ];
        //landscape css
        [htmlString appendString:@"<link rel='stylesheet' media='screen and (orientation: landscape)' href='landscape.css' type='text/css'/>"];
        //portrait css
        [htmlString appendString:@"<link rel='stylesheet' media='screen and (orientation: portrait)' href='portrait.css' type='text/css'/>"];

        [htmlString appendString:@"<link rel='stylesheet' href='style.css' type='text/css'/>"
         "<script type='text/javascript' src='jquery-1.6.2.min.js'></script>"
          "<script type='text/javascript' src='script.js'></script>"
         "</head>"
         ];

我也是在viewcontrollers中这样做的应该是AutorotateToInterfaceOrientation:方法

int i =0;
    switch (interfaceOrientation){
        case UIInterfaceOrientationPortrait:
            i = 0;
            break;
        case UIInterfaceOrientationPortraitUpsideDown:
            i = 180;
            break;
        case UIInterfaceOrientationLandscapeLeft:
            i = 90;
            break;
        case UIInterfaceOrientationLandscapeRight:
            i = -90;
            break;
    }
    [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.__defineGetter__('orientation',function(){return %d;});window.onorientationchange();",i]];

但是portrait.css从不用于纵向。看起来像定向肖像的媒体查询根本不起作用。

0 个答案:

没有答案