首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AIR - StageWebView on iPhone

AIR - StageWebView on iPhone
EN

Stack Overflow用户
提问于 2011-07-20 09:14:32
回答 5查看 6.7K关注 0票数 1

我正在使用FlashBuilder4.5构建一个iPhone应用程序。

为了显示广告,我计划使用StageWebView并加载一个包含广告代码的网页。

让我们说,广告将是320x50像素。因此,Actionscript代码看起来类似于以下内容:

代码语言:javascript
复制
adView = new StageWebView();
adView.loadURL("http://www.myadishere.com/ad.html");
var top:Number = navigator.actionBar.measuredHeight + 1
adView.viewPort = new Rectangle(0, top, 320, 50);
adView.stage = stage;

在应用程序中,我设置了applicationDPI="160",以便在iPhone3和iPhone4上运行时正确显示应用程序。然而,StageWebView的内容在iPhone4上看起来很小。如果我这样做,adView.drawViewPortToBitmapData()位图的大小是可以的。

因此,问题是如何使StageWebView内容相应地进行缩放,因此它看起来还可以,而不管屏幕是什么呢?

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2011-08-18 06:25:25

代码语言:javascript
复制
 You need to scale by yourself. Here is sample code.


<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" width="100%" height="100%" top="0">
    <fx:Declarations>
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.core.FlexGlobals;
            import mx.core.IVisualElement;
            import mx.events.FlexEvent;

            import spark.components.View;
            import spark.events.ViewNavigatorEvent;

            [Bindable]
            public var htmlText:String;
            public var url:String;
            private var swv:StageWebView;
            private function resizeSWV():void{
                var currentFlexScalingFactor:Number=FlexGlobals.topLevelApplication.runtimeDPI/FlexGlobals.topLevelApplication.applicationDPI;
                if(swv!=null){

    //swv.viewPort=new Rectangle(0, stage.stageHeight-height*currentFlexScalingFactor-FlexGlobals.topLevelApplication.tabbedNavigator.tabBar.height*currentFlexScalingFactor,width*currentFlexScalingFactor,height*currentFlexScalingFactor);

    swv.viewPort=new Rectangle(0, systemManager.screen.height*currentFlexScalingFactor-height*currentFlexScalingFactor-FlexGlobals.topLevelApplication.tabbedNavigator.tabBar.height*currentFlexScalingFactor,width*currentFlexScalingFactor,height*currentFlexScalingFactor);

                }
            }

        ]]>
    </fx:Script>
    <s:creationComplete>
        <![CDATA[
        swv=new StageWebView();
        resizeSWV();
        swv.stage=stage;


        var htmlString:String=htmlText;
        var urlL:String=url;

        swv.loadURL(url);
        (owner as View).addEventListener(ViewNavigatorEvent.REMOVING,
        function(event:ViewNavigatorEvent):void{
            swv.viewPort=null;
            swv.dispose();
            swv=null;
        }
        );
        ]]>
    </s:creationComplete>
    <s:resize>
        resizeSWV();
    </s:resize>
</s:Group>

 This is for TabbedViewNavigatorApplication.
票数 4
EN

Stack Overflow用户

发布于 2011-07-22 18:36:51

尝试在<head>部分中将以下代码添加到HTML中:

代码语言:javascript
复制
<meta name="viewport" content="width=XXXpx, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

用横幅/StageWebView宽度替换"XXX“。这应该会使图片以你想要的大小出现。

票数 2
EN

Stack Overflow用户

发布于 2011-08-01 15:02:01

@OMA我认为StageWebView是个小问题。当(在HTML中)我说:

代码语言:javascript
复制
<meta name="viewport" content="initial-scale=x.x">

iPhone应用程序崩溃了。任何“.-比例尺”都会使应用程序崩溃。如果没有“.-比例”指令,它就能正常工作。

我目前掌握的代码是:

代码语言:javascript
复制
<meta name="viewport" content="width=320px, height=50px, user-scalable=no"> 
<style type="text/css">

body, html {margin: 0 0; padding: 0 0; overflow: hidden;}
body {width: 320px; height: 50px;}
html {height: 50px;}

这是一种工作- ADL显示的内容不正确的大小,但在大多数情况下,iPhone本身显示的广告应该是。然而,有时广告以一半大小显示--不确定为什么--它与代码一直是完全相同的HTML页面和代码,但是广告显示的方式不同

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6759547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档