2011-07-20 10 views
1

私はiPhoneアプリケーションを構築するためにFlash Builder 4.5を使用しています。AIR - iPhoneのStageWebView

広告を表示するために、私はStageWebViewを使用し、広告コードを含むウェブページを読み込む予定です。

広告は320x50ピクセルと言います。だから、ActionScriptコードは、次のようになります。

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の上で実行するときに、アプリケーションが正しく表示されます。 しかし、iPhone4ではStageWebViewのコンテンツが小さく見えます。 私が行う場合adView.drawViewPortToBitmapData()ビットマップのサイズはOKです。

したがって、問題は、StageWebViewコンテンツをそれに応じて拡大する方法です。そのため、画面DPIに関係なくOKですか?

答えて

4
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. 
+0

ここに記載されている情報のいくつかは古くなっています。しかし、一般的な考え方は同じです。それは私のためにうまくいった4.6-SDK私は、私の銀河ネクサスに、私のネクサス1から私のxoomに今すぐ良いwebviewスケールを得ています。 – brybam

-1

まず、DPIを手動で設定する必要があるのはなぜですか?問題は、iphone 4のDPIが160よりもはるかに高いことです(私はそれが倍だと思っていますが、私の言葉を借りていません)。なぜアプリケーションが相対値(パーセンテージ)に基づいてサイズを変更するのではなく、解像度に応じてレイアウトが異なるだけでなく、 Capabilities.pixelAspectRatioをチェックしてdpiの内容を確認し、それに応じて変更することができます。

また、私の場合は、ほとんどのものに対してパーセンテージを使用しています。それはより良いサイズに変更され、コード全体が少なくなります。 <head>セクションでは、あなたのHTMLに次のコードを追加し

+0

私は「手動」アプリケーションを拡張することができますが、StageWebViewの内容に問題がまだ存在しています。 iPhone3では、viewPortのサイズは320x50pxですが、iPhone4では640x100pxです - どのようにしてビューポートのサイズに合わせてウェブページのコンテンツを拡大することができますか? – strah

+1

ビューポートのサイズに応じてStageWebViewに異なるサイズの '広告'を読み込ませることができます。それはパーセンテージに基づいてサイズ変更可能な広告か、 –

+0

割合に基づいて広告(HTMLコンテンツ)を調整するにはどうすればよいですか?私は 'viewport'メタタグで遊ぼうとしました。このタグのサポートは、StageWebViewでは実装されていないようです。残念ながら、DPIによって異なるコンテンツを読み込むことはオプションではありません。 – strah

2

試してみてください。

<meta name="viewport" content="width=XXXpx, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> 

バナー/ StageWebViewの幅を "XXX" を代入します。それはあなたが意図した大きさで絵を描写するはずです。

0

@OMA StageWebViewは少しバギーだと思います。 (HTMLで)次のように入力した場合:

<meta name="viewport" content="initial-scale=x.x"> 

iPhoneアプリがクラッシュします。任意の '...スケール'はアプリをクラッシュさせます。 '...-スケール'の指示がなければ、うまく動作します。

私が現時点で持っているコードは次のとおりです。

<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

を変化させる、私はそれを行う方法である - なぜわかりません:

<?xml version="1.0" encoding="utf-8"?> 
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" 
viewActivate="openSWV(event)" 
viewDeactivate="closeSWV(event)"> 

    <s:states> 
     <s:State name="portrait"/> 
     <s:State name="landscape"/> 
    </s:states> 

    <s:navigationContent> 
     <s:Button icon="@Embed('assets/icons/back.png')" label.landscape="Back" click="navigator.popView()"/> 
    </s:navigationContent> 

    <s:titleContent> 
     <s:Label text="Help" color="#FFFFFF" textAlign="center" fontWeight="bold" width="100%" /> 
    </s:titleContent> 

    <fx:Declarations> 
     <fx:String id="_help"> 
      <![CDATA[ 
      <html> 
      <body> 
      <p>Blah blah blah</p> 
      </body> 
      </html> 
      ]]> 
     </fx:String> 
    </fx:Declarations> 

    <fx:Script> 
     <![CDATA[ 
      import mx.core.FlexGlobals; 
      import mx.events.FlexEvent; 
      import flash.media.StageWebView; 

      private var _swv:StageWebView; 

      private function openSWV(event:Event=null):void { 
       _swv = new StageWebView(); 
       stage.addEventListener(Event.RESIZE, resizeSWV); 

       _swv.stage = stage; 
       resizeSWV(); 

       _swv.loadString(_help, 'text/html'); 
      } 

      private function closeSWV(event:Event=null):void { 
       stage.removeEventListener(Event.RESIZE, resizeSWV); 
       if (! _swv) 
        return; 
       _swv.dispose(); 
       _swv = null; 
      }   

      private function resizeSWV(event:Event=null):void { 
       if (! _swv) 
        return; 

       var scale:Number = FlexGlobals.topLevelApplication.runtimeDPI/FlexGlobals.topLevelApplication.applicationDPI; 

       // align to the right-bottom corner 
       _swv.viewPort = new Rectangle(stage.stageWidth - scale * width, stage.stageHeight - scale * height, scale * width, scale * height); 

      } 
     ]]> 
    </fx:Script> 
</s:View> 

私はSplitViewNavigatorを使用しているため、私は、右下隅に合わせます。

あなただけだけ使用し、下に整列する場合:

_swv.viewPort = new Rectangle(0, stage.stageHeight - scale * height, scale * width, scale * height); 
関連する問題