iOS8 + UIDeviceOrientationDidChangeNotification未被调用

Kam*_*pai 4 nsnotificationcenter uiinterfaceorientation ios swift

在我的工作应用程序(iOS 7.0.1)中,UIDeviceOrientationDidChangeNotification被调用.

现在,当我在iOS 8.0中运行此应用程序时,UIDeviceOrientationDidChangeNotification没有被调用.

尝试了很多,但没有运气.

编辑-1:

我使用下面的代码添加观察者的方向更改.适用于iOS 7,完美适用于iOS 8.

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

Azi*_*lah 13

在我的情况下,经过大量的搜索,我发现我犯了一个愚蠢的错误,我的设备potrait方向锁定.

请在设置中确认设备方向锁定.

这可能对某人有帮助.


iGW*_*iGW 3

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

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

>

-(void)didRotateDeviceChangeNotification:(NSNotification *)notification
{
    UIInterfaceOrientation newOrientation =  [UIApplication sharedApplication].statusBarOrientation;
    if ((newOrientation == UIInterfaceOrientationLandscapeLeft || newOrientation == UIInterfaceOrientationLandscapeRight))
    {

    }
}
Run Code Online (Sandbox Code Playgroud)