2012-04-11 13 views
0

私はアンドロイドとiphoneでSencha Touch 2フレームワークを開発しようとするアプリケーションがあります。 1つのビューを除き、アプリケーションの向きをポートレートのみに設定したい。 デバイスの向きが「横向き」の場合、デバイスの向きが「縦向き」または横向きの場合は、ポートレートビューが読み込まれます。sencha touch 2風景を除いた縦向きのデバイスの向きを1表示に固定

現在のところ、私は向きをポートレートとして固定しているアンドロイドのphonegapを使用しています。

しかし、方向に応じて、 "ポートレートビュー"または "ランドスケープビュー"のいずれかをロードするビューを作成すると、かなり失われます。 また、私がphonegapでポートレートの方向を固定している場合、向きが検出されますか?あなたのための

おかげで、私は自分自身にお答えします私の質問からどんな答えがなければ

答えて

1

を助けます。例えばアンドロイド(PhoneGapの)オン

としてマニフェスト向きに定義:場合、活性がアプリケーションを起動する前に、次にscreenOrientationが= "センサー"

アンドロイドアプリケーションでポートレートを使用する場合は、ポートレートのみに設定します。 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); super.loadUrl( "file:///android_asset/www/index.html");あなたが使用することをランドスケープ/ポートレイトを取得したい場合は、カスタムsetOrientationコードを呼び出すアクションをメインアプリケーションにコマンドを送信しますJSで

は、:

onSetOrientationSuccess: function(result) { 
    ... 
}, 
onSetOrientationError: function(err) { 
    ... 
}, 

setOrientation: function(orientation) { 

    PhoneGap.exec(this.onSetOrientationSuccess, this.onSetOrientationError, "OrientationPlugin", orientation, []); 
}, 

OrientationPluginは単なるPhoneGapのプラグインですあなたが行動をチェックし、右のコードを呼び出します。ここで

public class OrientationPlugin extends Plugin { 

public static final String ACTION="undefined"; 

@Override 
public PluginResult execute(String action, JSONArray data, String callbackId) { 
    Log.d("OrientationPlugin", "Plugin called"); 
    PluginResult result = null; 
    YourActivity activity = (YourActivity) this.ctx; 
    Log.d("OrientationPlugin", "Plugin Got context"); 

    if (ACTION.equals(action)) { 
     Log.d("OrientationPlugin", "Plugin set SCREEN_ORIENTATION_SENSOR");   
     activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); 
    } 
    else { 
     Log.d("OrientationPlugin", "Plugin set SCREEN_ORIENTATION_PORTRAIT");    
     activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);   
    } 
    Log.d("OrientationPlugin", "Plugin set ALL OK");    
    result = new PluginResult(Status.OK, "ok"); 
    return result; 
} 

}

をあなたが必要なときそして、あなたはいつでも戻っPORTRAITにそれを設定することができますそれはJSからです。

助けてください!

0

標準の向きを希望するビューでは、doLandscape: 1のようなカスタム値を追加します。 app.config.Runtimeクラスでランタイム "グローバル"値を設定したい場合は、アプリケーション全体で動作する場合はnavbarにアタッチします。ビューポートで

Ext.define(‘MyApp.config.Runtime’,{ 
    singleton : true, 
    config : { 
     doLandscape: 0 // initialize to 0 
    }, 
    constructor : function(config){ 
     this.initConfig(config); 
    } 
}); 

、追加:

onOrientationChange: function(viewport, orientation, width, height) { 
    // test trigger and values 
    console.log('o:' + orientation + ' w:' + width + ' h:' + height); 

    if (orientation == 'landscape' && MyApp.config.Runtime.doLandscape === 0) { 
     // most often this is all that's needed to prevent change 
     return false; 

     // alternatively/additionally set it back to portrait manually. 
     viewport.orientation = this.PORTRAIT; 
    } 
} 

が更新されたソースコードを見てみると、ここで向きの変更を処理し、発射ビューポートのデフォルトのコードです。

onOrientationChange: function() { 
    var currentOrientation = this.getOrientation(), 
     newOrientation = this.determineOrientation(); 

    if (newOrientation !== currentOrientation) { 
     this.fireOrientationChangeEvent(newOrientation, currentOrientation); 
    } 
}, 

fireOrientationChangeEvent: function(newOrientation, oldOrientation) { 
    var clsPrefix = Ext.baseCSSPrefix; 
    Ext.getBody().replaceCls(clsPrefix + oldOrientation, clsPrefix + newOrientation); 

    this.orientation = newOrientation; 

    this.updateSize(); 
    this.fireEvent('orientationchange', this, newOrientation, this.windowWidth, this.windowHeight); 
} 

あなたはネイティブパッケージ化されているように、このオプションは、別の代替として提供されています:

Ext.device.Orientation.on({ 
    scope: this, 
    orientationchange: function(e) { 
     console.log('Alpha: ', e.alpha); 
     console.log('Beta: ', e.beta); 
     console.log('Gamma: ', e.gamma); 
    } 
}); 
関連する問題