【问题标题】:How to get device orientation when the screen rotation is locked?屏幕旋转锁定时如何获取设备方向?
【发布时间】:2012-11-10 15:33:39
【问题描述】:

我使用通知来获取设备的方向。

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [notificationCenter addObserver:self  
                                   selector:@selector(deviceOrientationDidChange)           
                                       name:UIDeviceOrientationDidChangeNotification 
                                     object:nil];

但是当设备的屏幕旋转被锁定时,不会调用选择器函数。有什么帮助吗?

【问题讨论】:

  • “notificationCenter”设置正确吗?检查它是否不为零。你也可以试试这个语法:[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];
  • 你知道怎么做吗?我已经通过 XCode 锁定了方向,但使用 UIDevice.current.orientation 给出了解锁方向。即使设备实际上处于横向左侧。

标签: iphone objective-c ios device


【解决方案1】:

您可以使用加速度计来获取屏幕方向的值。见this。另见this博客

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多