【问题标题】:UIDeviceOrientationDidChangeNotification doesn't work while device is on table?设备在桌面上时 UIDeviceOrientationDidChangeNotification 不起作用?
【发布时间】:2011-10-19 16:41:31
【问题描述】:

您好,我有一个问题, 在我的AppDelegate 中,我使用了beginGeneratingDeviceOrientationNotifications 方法在设备开始旋转时开始通知我。 如果我手持 ipad,它可以正常工作,但是当它放在桌子上时,它不能按预期工作。 它会触发UIDeviceOrientationUnknown 通知。 此通知也会在 UI 启动后启动,而不是在初始屏幕上。

以下是我的代码:

if([[[PulseUIFactory Factory] GetUICreator] IsIPad])
    {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
    }
     current device stars giving proper values.
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

然后是我启动 UI 的地方

[self Launch_UI];

但通知在[self Launch_UI]; 调用后开始响应,即使通知在其调用之前已注册...

请提供任何帮助!!!

【问题讨论】:

    标签: iphone uidevice


    【解决方案1】:

    当您将设备放在桌子上时,[[UIDevice currentDevice] orientation] 将返回 UIDeviceOrientationFaceUp。然后,如果您的设备仍然正面朝上放在桌子上,无论您如何在桌子上旋转它,当前设备方向仍将是UIDeviceOrientationFaceUp

    如果设备在确定方向时遇到问题,您可能会收到UIDeviceOrientationUnknown。请参阅this 教程,了解如何使用UIDeviceOrientationDidChangeNotification 处理设备旋转。

    关于您的通知仅在加载 UI 后触发,UIDeviceOrientationDidChangeNotification 只会在设备旋转时触发。因此,如果您直到 U​​I 加载后才旋转设备,您将不会收到通知。如果这不是问题的原因,我必须查看更多代码才能更好地了解发生了什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-26
      • 2017-08-18
      • 2021-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-03
      • 1970-01-01
      相关资源
      最近更新 更多