2016-11-03 3 views
1

안녕하세요. nativescript에서 기기 방향을 설정하는 방법을 알고 싶습니다. 특히, 필자는 동일한 방향 (세로 방향)을 유지하면서 글자를 쓰고있는 응용 프로그램을 항상 회전시켜 장치를 회전시키지 않아도 가로 방향으로 들어가기를 원합니다.nativescript에서 방향을 설정하는 방법

nativescript-orientation 플러그인과 setOrientation을 사용해 보았습니다. 목록 플러그인

내가 정의의 속성 setOrientation을 읽을 수 없습니다 "라는 오류를 얻을 그러나
var orientation = require('nativescript-orientation'); 
console.log(JSON.stringify(orientation));// outputs JS: {} 
orientation.setOrientation("portrait"); 

. TNS는. 또한 나는 platforms/android 디렉토리를 제거하고 동일한 결과 tns platform add android를 실행하려고 플러그인이 설치되어 있는지 보여줍니다.

나는 또한 성공하지의 AndroidManifest.xml에 android:screenOrientation="portrait"의 다양한 조합을 가하고 시도.

의 AndroidManifest.xml을 App_resources이

처럼 보이는 내부에서
<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="__PACKAGE__" 
    android:versionCode="1" 
    android:versionName="1.0"> 

    <supports-screens 
     android:smallScreens="true" 
     android:normalScreens="true" 
     android:largeScreens="true" 
     android:xlargeScreens="true"/> 

    <uses-sdk 
     android:minSdkVersion="17" 
     android:targetSdkVersion="__APILEVEL__"/> 

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
    <uses-permission android:name="android.permission.INTERNET"/> 

    <application 
     android:screenOrientation="portrait" 
     android:name="com.tns.NativeScriptApplication" 
     android:allowBackup="true" 
     android:icon="@drawable/icon" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme"> 

     <activity 
      android:name="com.tns.NativeScriptActivity" 
      android:label="@string/title_activity_kimera" 
      android:configChanges="keyboardHidden|orientation|screenSize" 
      android:theme="@style/LaunchScreenTheme"> 
      <meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" /> 

      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name="com.tns.ErrorReportActivity"/> 
    </application> 
</manifest> 
+0

을 완성 했습니까? '빌드'를 완료 했습니까? 또한 장치/에뮬레이터에있는 현재 .apk를 제거한 다음 새 빌드를 '실행'또는 'livesync'해야 할 가능성이 높습니다. 매니페스트 옵션은 안드로이드 앱의 방향을 내가 아는 바대로 강제하는 더 나은 대안입니다. 그래서 작동하지만 오래된 .apk를 제거하지 않았다면 장치에 캐싱 문제가있을 수 있습니다 :) –

+0

apk를 삭제하고'tns run android'를 사용하여 실행합니다. 또한 안드로이드 manifest.xml을 추가했습니다. 뭔가를 놓친 경우 – xerotolerant

답변

10

내 응용 프로그램은 세로 방향입니다. 안드로이드의 경우 activity 태그 안에 AndroidManifest.xmlandroid:screenOrientation="portrait"을 추가하기 만하면됩니다. iOS의 경우 AndroidManifest.xml을 수정 한 후 open Xcode -> Select project on project navigator (left panel) -> Select target in middle panel -> Choose "General" tab -> Tick only "Portrait" in Deployment info section

+0

제안 해 주셔서 감사합니다. 그러나 이미 Android 매니페스트에 플래그를 추가했는데 작동하지 않는 것 같습니다. 내 게시물을 매니페스트로 업데이트했습니다. 아마 내가 틀린 장소에 깃발을 꽂았을거야? 너는 그것을보고 나에게 말해 줄 수 있니? – xerotolerant

+0

'activity' 태그 안에 넣습니다. 어디서 뒀어? –

+0

원본 파일을 전체 파일로 편집했습니다. – xerotolerant

관련 문제