本文介绍了如何强制导向模式在特定视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 做好与angularjs的前端框架的科尔多瓦应用程序。我想在的PhoneGap /科尔多瓦的应用程序的特定视图出现在横向模式。到目前为止,我所探讨的各种选项是:Doing an cordova app with angularjs as the frontend framework. I want a particular view in a phonegap/cordova app to appear in landscape mode. The various options I've explored so far are:设置 config.xml中。但是你想这只是如果你打算整个应用程序要么是在纵向或横向添加的manifest.json 。 (也照顾,我没有在我的config.xml中定义的任何方向设置)。我的计划是有条件包含的文件时,我想设置我的方向为横向。Setting the config.xml. But you'd want this only if you intend the whole app to either be in portrait or landscapeAdding manifest.json. (Also taking care that I do not have any orientation settings defined in my config.xml). My plan was to conditionally include the file when I want to set my orientation as landscape.因此​​,对于第二个选项,我写code在我的网页,例如:So for the 2nd option I've written code in my pages such as:<link rel="manifest" href="manifest.json" ng-if="orientation == 'landscape'"> ...并在控制器切换定位的价值 - 以迫使其对需求的意图...and in the controller toggling the value of orientation - with the intent of forcing it on demand.不过上面的方法不起作用。However the above approach doesn't work.如何使这项工作任何想法?Any idea on how to make this work?推荐答案我不知道有关angularjs一部分。但你可以尝试/使用 Orientationlock插件动态锁定和解锁方向。I don't know about the angularjs part. But you can try/use Orientationlock plugin to dynamically lock and unlock the Orientation.从插件描述从你的JavaScript code调用 window.plugins.orientationLock.unlock()解锁方向, window.plugins.orientationLock.lock (纵向)或 window.plugins.orientationLock.lock(风景)将屏幕锁定为指定的方向。From your JavaScript code call window.plugins.orientationLock.unlock() to unlock orientation, window.plugins.orientationLock.lock("portrait") or window.plugins.orientationLock.lock("landscape") to lock your screen to the specified orientation.要启动的应用程序科尔多瓦pre-锁定到位 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 或 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 在OnCreate()。To start your Cordova application pre-locked place setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); or setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); in the onCreate() of your Cordova activity.一旦解锁,您可以跟踪与常规orientationChange事件取向的变化:Once unlocked, you can track orientation changes with the regular orientationchange event:window.addEventListener("orientationchange", function() { alert(window.orientation);}); 这篇关于如何强制导向模式在特定视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-30 16:31