我一直在尝试使用Adobe Flex / Flash构建器StageWebView渲染网页,但它没有缩放网页以适应手机屏幕尺寸,并且基本上切断了网页的右侧。我尝试过使用
<meta name="viewPort" content="width=device-width; initial-scale=1.0;
maximum-scale=1.0; user-scalable=no;" />
这没效果。以下是我目前正在使用的Flex代码。
<?xml version="1.0" encoding="utf-8"?>
<fx:Script>
<![CDATA[
import flash.media.StageWebView;
import flash.net.URLRequest;
import spark.events.ViewNavigatorEvent;
protected var webView:StageWebView = new StageWebView();
protected var openBrowser:Boolean = false;
protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
{
if (StageWebView.isSupported)
{
currentState = "normal";
webView.stage = stage;
webView.viewPort = new Rectangle(0,75,stage.stageWidth,stage.stageHeight);
webView.addEventListener(LocationChangeEvent.LOCATION_CHANGE,onURLChange);
webView.loadURL("http://nealdrake.com/mls.html");
addEventListener(ViewNavigatorEvent.REMOVING,onRemove);
}
else {
currentState = "unsupported";
lblSupport.text = "StageWebView feature not supported";
}
}
protected function onURLChange(event:LocationChangeEvent):void
{
trace("URL change");
// Uncomment the following line to load in the default browser instead...
//navigateToURL(new URLRequest(event.location));
}
protected function onRemove(event:ViewNavigatorEvent):void
{
this.webView.dispose();
}
]]>
</fx:Script>
<s:states>
<s:State name="normal"/>
<s:State name="unsupported"/>
</s:states>
<s:Label id="lblSupport" includeIn="unsupported" width="95%" horizontalCenter="0" verticalCenter="0"/>
非常感谢任何帮助!
答案 0 :(得分:0)
我很惊讶它切断了右手侧而不是底部,因为这是我对此的期望:
webView.viewPort = new Rectangle(0,75,stage.stageWidth,stage.stageHeight);
您需要计算宽度和高度的任何X或Y偏移,如下所示:
webView.viewPort = new Rectangle(0,75,stage.stageWidth,stage.stageHeight - 75);
可能是在您的应用程序大小正确之前,您的StageWebView正在初始化。尝试添加一个resize处理程序(监听上面代码的任何组件上的Event.RESIZE事件),再次设置视口。