标签: device-orientation

iPad App因方向改变而崩溃

我正在开发一款iPad应用程序.我同时允许横向和纵向模式.我的UI在纵向模式下很好,但当我将其更改为横向模式时,我的UI变得混乱.我看到了一些与此相关的SO帖子,我在initWith中添加了以下代码...在我的UIView中.

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(abc)
                                             name:UIDeviceOrientationDidChangeNotification
                                           object:nil];
Run Code Online (Sandbox Code Playgroud)

这样做后,我的UI在纵向模式下工作正常.当我将其更改为横向模式时,我的用户界面很好.但在我将其更改回纵向模式后,我的应用程序崩溃了.我读了一些与应用程序崩溃相关的SO有关仪器的帖子.我启用了僵尸,发现正在向已发布的对象发送消息,此消息来自NSNotificationCenter.

除了注册我的设备之外,还有什么我需要处理的吗?另外,有什么方法可以将实现从UIView更改为UIViewController并实现UIViewController有关设备方向的方法?请让我知道我需要遵循的步骤才能完成这项工作.谢谢!

objective-c nsnotificationcenter device-orientation ios

3
推荐指数
1
解决办法
1680
查看次数

UIDEVICE方向

你好,我有我的启动画面,我想在横向模式和所有其他屏幕在potrait模式下显示.我的根视图控制器充当启动屏幕我在viewdidload方法中编写此代码

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight]; 
Run Code Online (Sandbox Code Playgroud)

但是这段代码没有用,并告诉我UI设备可能无法响应setorentation请指导我如何才能更改第一个启动画面的其他屏幕以及其他屏幕应该处于potrait模式

iphone user-interface objective-c device-orientation

2
推荐指数
1
解决办法
5445
查看次数

评估orientationEvent并设置一个值?

如果在发生方向更改时触发了onChange函数,如何在onChange中设置将更新jquery选择器的值.例如:

  $(document).ready(function(){    
    var onChanged = function() {
            if(window.orientation == 90 || window.orientation == -90){
                image = '<img src="images/land_100.png">';
            }else{
                image = '<img src="images/port_100.png">';
            }
     }
        $(window).bind(orientationEvent, onChanged).bind('load', onChanged);
        $('#bgImage').html(image); //won't update image
   });
Run Code Online (Sandbox Code Playgroud)

jquery orientation screen-orientation device-orientation

2
推荐指数
1
解决办法
6541
查看次数

谷歌地图js API V3:在"我的位置标记"上显示方向箭头

使用谷歌地图js API V3我很容易添加一个标记来显示用户的位置(基于navigator.geolocation).

如何添加指示用户移动方向的箭头(可能使用deviceorientation事件)?

编辑:这是我目前的代码:

function addUserLocation() {

    myLocationMarker = new google.maps.Marker({
        clickable : false,
        icon : new google.maps.MarkerImage('http://maps.gstatic.com/mapfiles/mobile/mobileimgs2.png', new google.maps.Size(22, 22), new google.maps.Point(0, 18), new google.maps.Point(11, 11)),
        shadow : null,
        zIndex : 999,
        title : 'me',
        map : map
    });

    enableWatchPosition();
}

function enableWatchPosition() {
    if (navigator.geolocation) {
        watchPositionId = navigator.geolocation.watchPosition(locateByBrowser, handleErrorGettingLocation, {
            timeout : 30000,
            enableHighAccuracy : true,
            maximumAge : 1000
        });
    }
}

function locateByBrowser(location) {

    var currentLocation = new google.maps.LatLng(location.coords.latitude, location.coords.longitude);
    myLocationMarker.setPosition(currentLocation);
}
Run Code Online (Sandbox Code Playgroud)

目前,位置标记只是一个蓝点.我想添加一个箭头,显示用户进入的方向,就像它出现在谷歌地图移动应用程序中一样.

当用户使用手机移动时,我想到使用deviceorientation事件来获取alpha值,然后按照alpha值旋转箭头图像,如下所示: …

google-maps-api-3 device-orientation

2
推荐指数
1
解决办法
3434
查看次数

调整浏览器窗口大小时,addEventListener 'resize' 不会触发

我需要检测手机视口宽度的变化。我使用以下代码来检测浏览器窗口的调整大小更改,但在调整窗口大小时 addEventListener 不会触发我的函数:

<html>
<head>
</head>
<body>

<div id="size">-</div><br>
<div id="orientation">-</div>

<script>

window.addEventListener('resize', sizeChanged() );

function sizeChanged() {

    var w=window.outerWidth;
    var h=window.outerHeight;
    var txt='<b>sizeChanged:</b><br> W=' + w + 'px<br> H=' + h+'px';
    document.getElementById('size').innerHTML=txt;
    console.log(txt);
}

window.addEventListener('orientationchange', orientationChanged() );

function orientationChanged() {

  var w=window.outerWidth;
  var h=window.outerHeight;
  var txt='<b>orientationChanged:</b><br> W=' + w + 'px<br> H=' + h+'px';
  document.getElementById('orientation').innerHTML=txt;
  console.log(txt);

}

</script>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我用 FF 62.0.3、Chrome 70.0.3538.77 和 IE11 测试了上面的代码。

有谁知道我的代码有什么问题?

javascript addeventlistener window-resize device-orientation

2
推荐指数
1
解决办法
4304
查看次数

Flutter Pageview 在方向变化时丢失索引

最近也有类似的问题,不过已经在 GitHub 上解决并关闭了。由于我是新手,我可能会在这里遗漏一些东西。方向更改后,页面索引恢复为零,但选定的 BottomNavigationBarItem 保持原样。这里正在显示页面“ONE”,但在旋转设备之前选择了选项卡“FOUR” 截屏


void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Pageview Orientation Bug',
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int _page = 0;
  PageController _controller = PageController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: OrientationBuilder(
        builder: (context,orientation) {
          return orientation == Orientation.portrait …
Run Code Online (Sandbox Code Playgroud)

device-orientation flutter flutter-layout flutter-pageview

2
推荐指数
1
解决办法
1439
查看次数

对于 iPad 的纵向和横向模式,保持 css 独立的首选方法是什么?

当我们制作 iPad 专用网站(我正在为桌面用户制作不同的网站)并且我们还想为纵向和横向模式编写不同的 CSS 时,您会更喜欢哪种方法?

第一种方法

我们可以只用一个 http 请求来保留单个 CSS 文件

<link href="style.css" rel="stylesheet" type="text/css" media="all" />
Run Code Online (Sandbox Code Playgroud)

并在内部使用媒体查询来保持代码分离

/* CSS for landscape here */

#wrapper {width:1024px}

/* CSS for portrait here */

@media only screen and (orientation:portrait){
#wrapper {width:768px}
}
Run Code Online (Sandbox Code Playgroud)

第二种方法

我们可以使用 2 个 CSS 文件和 2 个 http 请求

<!--CSS for landscape-->
<style type="text/css" media="only screen and (min-device-width: 768px) and (max-device-width: 1024px)">

<!--CSS for portrait-->
<style type="text/css" media="only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)">
Run Code Online (Sandbox Code Playgroud)

您更喜欢哪种方法,如果您有任何改进建议,请告诉我们。

注意:我正在为 …

css mobile-safari ipad device-orientation media-queries

1
推荐指数
1
解决办法
1734
查看次数

标准化设备方向数据

我在 JavaScript 中玩设备方向,我注意到我的 Ipad(iOS 6.1)和我的 Nexus7(Android 4.2.2)之间存在一些差异。

此代码与 Ipad 和 Nexus7 打印的数据不同。

<html>
  <head/>
  <body>
    <button id="calibrate">Calibrate</button>
    <button id="stop">Stop</button>
    <button id="play">Play</button>
    <div id="log"><p></p></div>
    <script>
      var log = document.getElementById('log');
      var calibrate = false;
      var calibrateG = 0, calibrateB = 0, calibrateA = 0;

      var deviceorientation = function(e) {
        if (calibrate) {
          calibrateG = e.gamma;
          calibrateB = e.beta;
          calibrateA = e.alpha;
          calibrate = false;
        }

        var gamma = parseInt(e.gamma - calibrateG);
        var beta = parseInt(e.beta - calibrateB);
        var alpha = parseInt(e.alpha - …
Run Code Online (Sandbox Code Playgroud)

javascript android device-orientation ios gyroscope

1
推荐指数
1
解决办法
3577
查看次数

Android SensorManager.getOrientation()返回-PI/2和PI/2之间的音高

我正在设计一个需要检查设备方向的应用程序(方位角,俯仰和滚动).我使用以下代码来实现此目的:

@Override
public void onSensorChanged(SensorEvent event) {
    if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
        gravityMatrix = event.values.clone();// Fill gravityMatrix with accelerometer values
    else if(event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
        geomagneticMatrix = event.values.clone();// Fill geomagneticMatrix with magnetic-field sensor values
    if(gravityMatrix != null && geomagneticMatrix != null){
        RMatrix = new float[16];
        IMatrix = new float[16];

        SensorManager.getRotationMatrix(RMatrix, IMatrix, gravityMatrix, geomagneticMatrix);// Retrieve RMatrix, necessary for the getOrientation method
        SensorManager.getOrientation(RMatrix, orientation);// Get the current orientation of the device
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我可以从'orientation'float []获得方位角,俯仰和滚动值.方位角和滚动值的一切都很好(它返回正确的角度),但是当我打印音高值(方向[1])时,我总是检索PI/2和-PI/2之间的角度.我不明白为什么?我无法检索大于PI/2或小于-PI/2的角度.只要我有+的角度 - PI/2和我一直在我的旋转设备(三星Galaxy S2)的角度突然减小它达到了PI/2的值之后.

任何人都可以解释为什么俯仰角表现得如此不寻常?

提前致谢!

android angle motion-detection device-orientation android-sensors

1
推荐指数
1
解决办法
2694
查看次数

SwiftUI iPadOS 应用程序根据方向更改文本

我想根据设备方向更改显示的文本。视觉将描述我正在努力实现更好的目标:)

这里是横向模式 横向模式 这是纵向模式 纵向模式

我想在纵向模式下显示月份名称的短格式,并找到了各种描述如何通过检测设备方向来实现这一点的帖子。我还发现这不在最佳实践类别中,所以想知道是否有更好的方法。代码只是一个 VStack,在 ScrollView 中有两个 Text 组件。

text device-orientation swiftui

1
推荐指数
2
解决办法
1302
查看次数