状态栏旋转通知

时间:2013-02-18 17:44:52

标签: iphone ios objective-c uiview uistatusbar

我想知道状态栏何时旋转。接收屏幕旋转通知可能会使问题与“正面朝上”和“正面朝下”等方向混淆。因此,根据状态栏的方向管理轮换是最简单,最干净的方法。当方向发生变化时如何收到通知?

2 个答案:

答案 0 :(得分:12)

您需要注册UIApplicationDidChangeStatusBarOrientationNotification通知。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];

- (void)statusBarOrientationChange:(NSNotification *)notification {
    UIInterfaceOrientation orient = [notification.userInfo[UIApplicationStatusBarOrientationUserInfoKey] integerValue];

    // handle the interface orientation as needed
}

请注意,此方法永远不会导致“面朝上”或“面朝下”设备方向,因为这只涉及界面方向。

答案 1 :(得分:-1)

//register to receive orientation notifications somewhere:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:UIDeviceOrientationDidChangeNotification object:nil];


    -(void)detectOrientation{

        switch ([[UIDevice currentDevice] orientation]) {

            case UIDeviceOrientationFaceDown:{
            }
            break;

            default:{
            }
            break;

        }
    }

如果不能正常工作,请检查方向锁!浪费了几个小时。

相关问题