모든 플랫폼에서 이온 모드에서만 앱을 세로 모드로 제한하는 방법은 무엇입니까?
Ionic / Cordova에서 일하고 있는데 이것을 추가 androidManifest.xml
했지만 이것이 효과가 없었으며 앱이 여전히 두 가지 방식으로 표시됩니다.
android:screenOrientation="portrait"
앱을 세로 모드로만 제한하려면 어떻게해야합니까? 안드로이드를 확인했는데 작동하지 않습니다
모든 장치에서만 세로 모드로 제한하려면이 루트를 프로젝트 루트 폴더의 config.xml에 추가해야합니다.
<preference name="orientation" value="portrait" />
그런 다음 명령 행에 아래 텍스트를 입력하여 플랫폼을 다시 빌드하십시오.
ionic build
이온 v2 + 업데이트
Ionic 버전 2 이상의 경우, 플러그인 및 플러그인을 포함하여 사용하는 모든 플러그인에 해당하는 Ionic Native 패키지 도 설치해야합니다 .cordova-plugin-
phonegap-plugin-
이온 네이티브 플러그인 설치
CLI 에서 플러그인 용 Ionic Native의 TypeScript 모듈을 설치하십시오 .
$ ionic cordova plugin add --save cordova-plugin-screen-orientation $ npm install --save @ionic-native/screen-orientation
*
--save
명령은 선택 사항이며 플러그인을package.json
파일에 추가하지 않으려면 생략 할 수 있습니다.가져 오기
ScreenOrientation
플러그인플러그인을 문서 로 가져올
controller
수있는 자세한 정보 로 가져옵니다 .import { ScreenOrientation } from '@ionic-native/screen-orientation'; @Component({ templateUrl: 'app.html', providers: [ ScreenOrientation ] }) constructor(private screenOrientation: ScreenOrientation) { // Your code here... }
당신의 일을
화면 방향을 프로그래밍 방식으로 잠금 및 잠금 해제합니다.
// Set orientation to portrait this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT); // Disable orientation lock this.screenOrientation.unlock();
보너스 포인트
현재 방향을 얻을 수도 있습니다.
// Get current orientation console.log(this.screenOrientation.type); // Will return landscape" or "portrait"
https://cordova.apache.org/docs/en/4.0.0/config_ref/#global-preferences 에 따르면 ,
방향을 사용하면 방향을 고정하고 방향 변경에 따라 인터페이스가 회전하는 것을 방지 할 수 있습니다. 가능한 값은 기본값, 가로 또는 세로입니다. 예:
<preference name="Orientation" value="landscape" />
이 값은 대소 문자를 구분하며 "방향"이 아니라 "방향"입니다.
먼저 다음을 사용하여 Cordova 화면 방향 플러그인 을 추가해야합니다.
cordova plugin add cordova-plugin-screen-orientation
다음 추가 screen.lockOrientation('portrait');
로 .run()
방법
angular.module('myApp', [])
.run(function($ionicPlatform) {
screen.lockOrientation('portrait');
console.log('Orientation is ' + screen.orientation);
});
})
오리엔테이션에서 무언가를 원한다면 앱 오리엔테이션을 변경할 때 어떤 조치를 취하고 싶을 때 이온 프레임 워크 플러그인을 사용해야합니다 ... https://ionicframework.com/docs/native/screen-orientation/
세로 또는 가로 모드로 앱을 제한하려면 config.xml에 다음 줄을 추가하면됩니다.
<preference name="orientation" value="portrait" />
OR
<preference name="orientation" value="landscape" />
각도 내부에 다음 과 같이 app.js
선을 추가하십시오 screen.lockOrientation('portrait');
.
과
angular.module('app', ['ionic'])
.run(function($ionicPlatform) {
// LOCK ORIENTATION TO PORTRAIT.
screen.lockOrientation('portrait');
});
})
You will also have other code in the .run
function, but the one you are interested in is the line I wrote. I haven't added the line <preference name="orientation" value="portrait" />
in my code, but you may need to add the cordova-plugin-device-orientation
In config.xml add the following line
<preference name="orientation" value="portrait" />
You can try this:-
Cordova plugin to set/lock the screen orientation in a common way for iOS, Android, WP8 and Blackberry 10. This plugin is based on an early version of Screen Orientation API so the api does not currently match the current spec.
https://github.com/apache/cordova-plugin-screen-orientation
or try this code in xml config:-
<preference name="orientation" value="portrait" />
Please add android:screenOrientation="portrait"
in the androidManifest.xml
file as an attribute of activity tag for android.
<activity
android:name="com.example.demo_spinner.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
'programing tip' 카테고리의 다른 글
rc.exe로 인해 Visual Studio를 빌드 할 수 없습니다 (0) | 2020.07.26 |
---|---|
밑줄 : 여러 속성에 따른 sortBy () (0) | 2020.07.26 |
PHP7 : ext-dom 문제 설치 (0) | 2020.07.26 |
안드로이드 디렉토리에 파일을 나열하는 방법? (0) | 2020.07.26 |
DataTable : 항목 표시 드롭 다운을 숨기고 검색 상자는 유지 (0) | 2020.07.26 |