【问题标题】:Status bar rotation notification状态栏旋转通知
【发布时间】:2013-02-18 17:44:51
【问题描述】:

我想知道状态栏何时旋转。接收屏幕旋转通知可能会将事情与“面朝上”和“面朝下”等方向混淆。因此,根据状态栏的方向管理旋转是最简单和最干净的方法。方向改变时如何收到通知?

【问题讨论】:

    标签: iphone ios objective-c uiview uistatusbar


    【解决方案1】:

    您需要注册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
    }
    

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

    【讨论】:

    • 这实际上给了我以前的方向而不是当前的新方向。切换到[[UIApplication sharedApplication] statusBarOrientation] 给了我新的状态栏方向
    【解决方案2】:
    //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;
    
            }
        }
    

    如果它不起作用,请检查方向锁定!浪费了几个小时。

    【讨论】:

    • 问题是关于状态栏方向的变化,而不是设备方向的变化。
    猜你喜欢
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多