我实现了一个嵌入了视频播放器的电子阅读器,我需要一个从播放器切换全屏模式的选项.
我的问题如下:
这是在全屏播放视频的最佳方式,让用户从此状态返回到之前正在阅读的页面,并保留视频的当前时间.
我需要处理的另一个复杂情况是:
在纵向和横向上有一个页面的不同可视化,如果用户在纵向上切换全屏并旋转设备,则视频应转到横向模式并重新缩放视频以适合屏幕,但如果用户从此页面返回,则应该再次回到肖像.
如果需要,我可以提供更多信息.提前致谢
android screen-orientation android-video-player orientation-changes android-orientation
描述
我有一个活动,在表面视图上显示相机预览.我不希望它在方向更改时重新启动(因为它不断扫描QR码),因此方向被锁定为纵向.
我遇到的问题是我需要在屏幕底部向用户显示屏幕上的说明.鉴于屏幕被锁定在一个方向,我不会收到新方向的通知,因为活动没有重新绘制.因此,无论手机处于纵向,纵向,横向还是尊重的景观,指令都在同一个地方呈现.
为了解决这个问题,我联系了传感器管理器,实时读取方向.(请参阅下面的代码)阅读完之后,我自己制定了方向,并根据需要移动我的说明,因为每次更新都会发送给我.到目前为止,这一直对我有用.在华硕Transformer Prime和Xoom平板电脑上进行测试时.平板电脑将方向返回为"90"表示纵向,而不是像其他2部手机一样返回"0".因此,您可以在下面的代码中看到,我检查平板电脑(大屏幕)并减去额外的90度.
问题
问题是新的Nexus 7平板电脑没有这种额外的偏见.在肖像中它返回"0",但我将其检测为平板电脑,因此减去90度因此结果为270并且它将我的指示放置为平板电脑处于横向模式.我假设背后的原因是Xoom/Transformer设计用于横向,Nexus用于纵向,但除非我知道所有受影响的设备,否则无济于事.
题
是否有一种可靠的方法来检测所有设备的方向并"实时"返回结果,如下面的代码所示,但是考虑到设备的默认方向(即Phones + Nexus 7是纵向,但大多数平板电脑都是景观)?
现行守则
boolean large = ((getBaseContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
boolean xlarge = ((getBaseContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
isTablet = large || xlarge;
myOrientationEventListener = new OrientationEventListener(getBaseContext(), SensorManager.SENSOR_DELAY_NORMAL)
{
@Override
public void onOrientationChanged(int orientation)
{
if (orientation == -1)
{
return;
}
if (isTablet)
{
orientation += -90;
if (orientation < 0) // keep the result between 0-360
{
orientation += 360;
}
}
// Work out the …Run Code Online (Sandbox Code Playgroud) android sensor orientation screen-orientation android-sensors
我正在捕捉这样的orientationchange事件:
$(window).bind( 'orientationchange', function(e){
});
Run Code Online (Sandbox Code Playgroud)
如何获得新的屏幕宽度和高度(以像素为单位)orientationchage?
我已经尝试screen.width但是这没有改变,它仍然是初始宽度,即使在方向改变之后.
我的屏幕尺寸为600(宽)x 1024(高).我得到当前宽度600但错误地获得高度976(没有旋转屏幕).我得到当前宽度1024但错误得到高度552(旋转屏幕).
int rowPixelWidth = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
int rowWidth = (int)Math.floor(rowPixelWidth / this.getResources().getDisplayMetrics().density);
int rowPixelheight = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight();
int rowheight = (int)Math.floor(rowPixelheight / this.getResources().getDisplayMetrics().density);
Log.d("rowWidth","rowWidth"+rowWidth);
Log.d("rowheight","rowheight"+rowheight);
-------------------------------------------------------------
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="8" />
<supports-screens android:anyDensity="true"/>
-------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
这段代码出了什么问题?
以下是典型屏幕宽度的一些数字:
我获得当前宽度但没有获得所有设备的当前高度(没有(320x480屏幕).
我尝试以像素为单位获取屏幕尺寸的代码,但同样会出现问题.
我有一个视频播放器,我有两个功能:
如果禁用了自动旋转,并且当用户单击全屏按钮时,我会强制orientation进入landscape视图,setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)并在退出全屏时返回纵向视图.
onConfigurationChanged当用户启用自动旋转功能时,我已覆盖以检测方向的变化,并根据方向更改活动视图.
现在这个设置的问题是,如果用户启动活动并进入全屏并且setRequestedOrientation被调用一次,稍后auto-rotate启用时,活动不会收到方向更改并且onConfigurationChanged不会被调用.
我在这里(/sf/answers/427644451/)读到他们不会同时工作.
我想知道是否有一种方法可以实现两者,因为我已经看过玩家喜欢MX Player在他们的应用程序中执行此操作.
android orientation screen-orientation autorotate screen-rotation
我的要求是将应用程序固定为手机上的纵向模式和选项卡上的横向模式,从闪屏开始。尝试使用 ionic native 上可用的 Screen Orientation 插件,但对我不起作用。
我尝试过的事情:
在 app.component.ts 上:
constructor(..., private screenOrientation: ScreenOrientation) {
platform.ready().then(() => {
this.screenOrientation.lock('landscape');
ScreenOrientation.lockOrientation('landscape');
screen.msLockOrientation('landscape');
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);
Run Code Online (Sandbox Code Playgroud)
我也在 home.ts 上尝试了上述所有行,但没有奏效。当我设置:
console.log(this.screenOrientation.type);
Run Code Online (Sandbox Code Playgroud)
这将在日志中正确打印出屏幕方向。每当我设置 subscribe 方法时,它也会在屏幕方向发生变化时提醒我,这意味着所有导入语句都可以正常工作并且我能够正确访问插件方法。我能够在 Android 和 iOS 上复制这个问题。任何帮助将不胜感激。
平台/库/依赖项详细信息:
"@angular/common": "4.1.3",
“离子角”:“3.6.0”,
“离子”:“3.7.0”
目前在 Activity 类中使用此代码块来进入粘性沉浸模式:
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus && android.os.Build.VERSION.SDK_INT > 15) {
var flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_FULLSCREEN
flags = if (android.os.Build.VERSION.SDK_INT < 19) flags
else flags or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
window.decorView.systemUiVisibility = flags
}
}
Run Code Online (Sandbox Code Playgroud)
当方向切换时,状态栏会回来(甚至不是半透明的)并保持不变,直到拖动,然后再次消失。我真的不明白这种行为的原因,我该如何解决它?
先感谢您。
TL;DR:iOS 文档不同意Info.plist哪个方向(横向左与右)在哪一侧有主页按钮。我错过了什么吗?(例如,代码认为它所处的方向与设备知道它所处的方向之间存在区别。请参阅下面标记为 ? 的倒数第二个要点。)
但是,当我在 Xcode 中使用 General 复选框时,Info.plist文件显示相反:
上述信息足以清楚地说明矛盾。我的问题是:我是否遗漏了某些东西,或者我应该将其视为工具链/文档/API 中的长期残留物?
您会问,当应用程序在模拟器或设备上运行时,实际会发生什么?以下是我收集的数据的一个子集。为了您的阅读方便,我强调了LEFT 和RIGHT 这两个术语。你的大脑可能仍然会爆炸。
需要跟踪三个数量:
UIDevice.current.orientation说明了什么。当 General 复选框单独设置为 "Landscape LEFT" 时:
Info.plist文件说“横向(左主页按钮)”[即不同意文档]UIDevice.current.orientation == .landscapeRIGHT [即不同意Xcode,但同意模拟器菜单]UIDevice.current.orientation == .landscapeLEFT [与文档一致/与Xcode/plist相反]我使用了其他问题中的几种方法来尝试锁定我的网络应用程序的屏幕方向,但锁定方向总是失败。这是我的代码:
// lock orientation to portrait
window.screen.lockOrientationUniversal = window.screen.lockOrientation || window.screen.mozLockOrientation || window.screen.msLockOrientation;
if (window.screen.lockOrientationUniversal("portrait")) {
console.log("Orientation locked to portrait");
} else {
console.log("Orientation lock failed.");
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过用 justscreen.而不是window.screen.得到同样的结果。请注意,这是在最新的 Android 版 Firefox 上进行测试,并且该网络应用程序不是全屏应用程序。
我还收到以下消息:
不推荐使用方向传感器。
这是有道理的,因为Mozilla 网站提到它已被弃用。最新支持的方法是什么?
我正在开发一个使用视图控制器的应用程序,并且正在慢慢迁移到使用使用 SwiftUI 构建的视图。
我正在开发新的 swiftUI 视图,因此我将 UIHostingController 设置为 SceneDelegate 中的 rootViewController
总的来说,我的整个应用程序仅限于此处的纵向
我希望允许在左侧纵向和横向显示一些个人视图
这是我到目前为止所使用的 swiftUI,它在 iOS 15 中完美运行
在 AppDelegate 我有
static var orientationLock = UIInterfaceOrientationMask.portrait
Run Code Online (Sandbox Code Playgroud)
然后在方法中
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask
Run Code Online (Sandbox Code Playgroud)
这设置为返回
return AppDelegate.orientationLock
Run Code Online (Sandbox Code Playgroud)
然后在特定的 swiftUI 文件中我想要允许旋转,我只需通过将此修改器添加到主视图来处理屏幕旋转
.onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
if orientation.isLandscape {
AppDelegate.orientationLock = UIInterfaceOrientationMask.landscapeLeft
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
UINavigationController.attemptRotationToDeviceOrientation()
} else {
AppDelegate.orientationLock = UIInterfaceOrientationMask.portrait
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
UINavigationController.attemptRotationToDeviceOrientation()
}
}
.onDisappear {
DispatchQueue.main.async {
AppDelegate.orientationLock = UIInterfaceOrientationMask.portrait
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
UINavigationController.attemptRotationToDeviceOrientation() …Run Code Online (Sandbox Code Playgroud) android ×5
ios ×2
javascript ×2
orientation ×2
angular ×1
autorotate ×1
ionic-native ×1
ionic2 ×1
ionic3 ×1
ios16 ×1
jquery ×1
kotlin ×1
landscape ×1
mobile ×1
sensor ×1
swiftui ×1