我正在尝试在我的网站上实现DeviceOrientationEvent和DeviceMotionEvent以获得3D效果。但是,该控制台不会记录任何信息,并且显然iOS 13需要用户设置权限才能开始执行此操作。我似乎无法弄清楚如何正确设置它。
我已经做了一些研究,这就是我发现的东西:https : //github.com/w3c/deviceorientation/issues/57#issuecomment-498417027
可悲的是,在线提供的所有其他方法不再可用。
window.addEventListener('deviceorientation', function(event) {
console.log(event.alpha + ' : ' + event.beta + ' : ' + event.gamma);
});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息:
[警告]在请求并授予许可之前,不会触发任何设备运动或定向事件。
javascript safari mobile-safari device-orientation devicemotion
我使用splitviewcontroller作为我的应用程序的根视图.我需要在splitviewcontroller之上将登录和注册视图显示为模态视图.当我尝试从splitViewController的rootview的viewdidAppear方法呈现login/reg视图时,它没有显示出来.我尝试使用以下代码从Appdelegate的didFinishLaunching方法中显示login/reg视图
[self.window.rootViewController presentModalViewController:self.navController animated:NO];
Run Code Online (Sandbox Code Playgroud)
它的工作原理.
我的问题是,应用程序支持横向方向,但是当我在设备中运行它时,无论我在哪个方向上握住设备,我都只使用LandscapeRight作为方向.因此,如果我将设备保持在LandscapeLeft方向,应用程序将登录屏幕颠倒.我在info.plist上使用支持方向的LandscapeLeft&Right.
请帮我解决这个问题.当我们将splitViewcontroller作为应用程序的根视图时,我们将如何呈现视图?
在iOS 5.0(仅)中,我能够从splitviewcontroller的rootview控制器 - viewdidAppear方法呈现登录视图.在所有其他操作系统版本中,这种情况不起作用,我需要从Appdelegate的didFinishLaunching方法中呈现它.
ipad uisplitviewcontroller uiinterfaceorientation device-orientation ios
是否存在本机JavaScript(或通过使用诸如JQuery/Modernizr等库)来检测设备是否能够改变方向?我想用它作为区分桌面和移动设备的方法.
谢谢,
沙迪
javascript jquery orientation device-orientation orientation-changes
我有一个支持设备方向的屏幕.
一切都工作得很好,除了当我将设备上下颠倒(顶部的主页按钮)时,旋转不起作用(它停留在最后的风景设置上).
我知道有几个地方需要更新以支持这个:



我在这里错过了什么?
这很奇怪.我正在玩设备方向,但似乎无法使用rotateX和rotateY在Safari(iOS 8.0.2)中工作.
但!如果我使用支持apple-web-app的元标记将其保存到我的主屏幕,它可以正常工作.
这是我的脚本:
$( document ).ready(function() {
window.addEventListener("deviceorientation", handleOrientation, true);
function handleOrientation(e) {
var alpha = e.alpha;
var beta = e.beta;
var gamma = e.gamma;
$('#z').val(Math.round(alpha)); // Z
$('#x').val(Math.round(beta)); // X
$('#y').val(Math.round(gamma)); // Y
document.getElementById("box").style.webkitTransform="rotateZ("+Math.round(-alpha)+"deg) rotateX("+Math.round(beta)+"deg) rotateY("+Math.round(-gamma)+"deg)";
}
});
Run Code Online (Sandbox Code Playgroud)
你可以在这里看到它(在你的iPhone上):http://kohlin.net/matte/orientation.html 然后尝试将其保存到你的主屏幕.
有线索吗?一个bug?
我目前正在开发广泛使用deviceOrientation和deviceMotion HTML5 API的移动Web应用程序.在大多数移动浏览器中,事件每50毫秒触发一次,这对我所需的精度来说太慢了:有没有办法以更高的速率获取运动数据?
我查看了W3C DeviceOrientation事件规范,我发现事件的interval属性给出了触发率devicemotion,不幸的是readonly(另外,我不确定这是否只是浏览器实现的刷新率的指标,或者如果这实际上设置了浏览器的刷新率).我看到该initAccelerometerEvent方法可能允许更改此值,但我无法在我的Javascript代码中找到如何直接使用它.
或者,我认为我们可以获得加速度计/陀螺仪的当前值:如果存在这样的方法,我们可以在setInterval方法中使用它,以便我们设置我们想要的刷新率.不幸的是,我找不到这样的方法.
因此,任何以更高的速率获得运动值的建议都是最受欢迎的.非常感谢您的帮助!
我在我的应用程序中使用ROTATION_VECTOR类型的传感器数据.
使用我的Nexus 5,我可以从方向[0]获得方位角,并且可以使手机朝向下图所示的范围(这是非常准确的).
由于我在不同的设备上尝试了我的应用程序,我发现传感器值与我的Nexus 5测试设备不同.在我的三星Galaxy Nexus和三星Galaxy S3 Mini上,方位角受到倾斜设备的影响,如图所示.
TYPE_ROTATION_VECTOR正在使用传感器融合,这就是我使用传感器测试应用检查不同设备上的单个传感器值的原因.在Nexus 5上,当倾斜设备时,z轴的方向值保持大致相同,在三星Galaxy Nexus上,z的值在倾斜时变化(从直立到躺着大约90°).我担心传感器融合正在使用这些值,这就是为什么我的方位角在不同的设备上是不同的.
有没有人遇到类似的情况,甚至更重要的是:有没有人有解决方法或不同的方式来接收方位角?
为了确保,我寻找后置摄像头指向的方向......
这是我的代码:
final float[] mRotationMatrix = new float[9];
final float[] mRotationMatrixFromVector = new float[9];
final float[] orientation = new float[3];
Run Code Online (Sandbox Code Playgroud)
...
SensorManager.getRotationMatrixFromVector(mRotationMatrixFromVector,
event.values);
// enables usable range like in picture
SensorManager.remapCoordinateSystem(mRotationMatrixFromVector,
SensorManager.AXIS_X, SensorManager.AXIS_Z,
mRotationMatrix);
SensorManager.getOrientation(mRotationMatrix, orientation);
Run Code Online (Sandbox Code Playgroud) android azimuth device-orientation android-sensors sensor-fusion
我试图改变deviceorientation沿左右轴和上下轴的两个事件之间的方向,这些轴通常被定义为电话x和y轴(https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Orientation_and_motion_data_explained)
即瞬间之间t1和t2其中那些电话线从移动(x1, y1)到(x2, y2),它想获得(angle(x2-x1), angle(y1-y2)).
当设备处于纵向模式时(与横向模式相反),这些轴似乎对应于beta和gamma.然而,当手机处于垂直状态(底部朝向地面)时,该gamma值变得非常不稳定,并且从90度跳到-90度(在相同的情况下,alpha跳跃180度)您可以在手机上轻松看到
我想避免这种情况,并且还获得360范围内的值.这是我到目前为止:
// assuming portrait mode
var beta0, gamma0;
window.addEventListener('deviceorientation', function(orientation) {
if (typeof beta0 === 'undefined') {
beta0 = beta;
gamma0 = gamma;
}
console.log('user has moved to the left by', gamma - gamma0, ' and to the top by', beta - beta0);
});
Run Code Online (Sandbox Code Playgroud)
当设备大部分是水平的时候工作正常,而当它是垂直的时候根本不工作
它是一个超类文件名Apporientationviewcontroller.h/m.我在所有其他子类中调用这个超类.因此,如果" isPortraitModeONN "为" ON ",则所有屏幕仅应在纵向模式下工作.如果用户尝试将设备更改为横向,则不应旋转.如果开关处于" 开 "状态,它应该始终处于纵向模式.在我的情况下,在笑的应用程序时,它处于纵向模式.但是,如果我旋转屏幕,它会改变为景观.但在设置中关闭开关之前不应改变其方向.
if(isPortraitModeONN)
{
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}
else
{
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft){
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];
}
else{
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
}
Run Code Online (Sandbox Code Playgroud) 在 iOS 13 中,Apple 引入了 API DeviceOrientationEvent.requestPermission。它必须由用户操作(单击、点击或等效操作)触发。我的问题是结果似乎被缓存了,所以如果用户拒绝许可,我不能再次请求访问(使用缓存值自动实现承诺)。有什么方法可以强制设备忘记缓存的值并再次请求用户访问方向数据的权限(我的意思是它应该再次显示用户可以允许或拒绝访问的弹出窗口)?
这是相关代码:
if (DeviceOrientationEvent && typeof(DeviceOrientationEvent.requestPermission) === "function") {
const permissionState = await DeviceOrientationEvent.requestPermission();
if (permissionState === "granted") {
// Permission granted
} else {
// Permission denied
}
}
Run Code Online (Sandbox Code Playgroud) ios ×5
javascript ×4
devicemotion ×2
html5 ×2
android ×1
azimuth ×1
css ×1
euler-angles ×1
ipad ×1
iphone ×1
jquery ×1
mobile ×1
objective-c ×1
orientation ×1
rotation ×1
safari ×1