Objective c 只能获得上一个旋转

Objective c 只能获得上一个旋转,objective-c,ios,uideviceorientation,Objective C,Ios,Uideviceorientation,在我的对象初始化方法中 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(didRotate:) name:@"UIDeviceOrie

在我的对象初始化方法中

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(didRotate:)
                                                    name:@"UIDeviceOrientationDidChangeNotification" 
                                                  object:nil];
旋转法

- (void) didRotate:(NSNotification *)notification {

    NSLog(@"rotate notification");

    //MA_MobileAppDelegate *appDelegate = (MA_MobileAppDelegate *)[[UIApplication sharedApplication] delegate];

    //UIInterfaceOrientation orientation = appDelegate.tabBarController.interfaceOrientation;
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

出于某种原因,didRotate似乎在实际旋转之前被调用。因此,当我尝试获得当前/最终旋转时,我会得到最后一个旋转。只有一个视图控制器似乎不是这样。知道我做错了什么吗?

iOS跟踪两个不同的方向:设备方向(
[[UIDevice currentDevice]方向]
)和接口方向(
[[UIApplication sharedApplication]statusBarOrientation]
)。设备方向的改变可能触发接口方向的改变。在系统更改接口方向之前,您将收到设备方向更改通知

试着观察。它是由
[UIApplication sharedApplication]
发布的。我不得不推迟我的代码

[self performBlock:^(id sender) {

//rotation code

} afterDelay:0.1f];

只需短暂延迟,UIApplication就有时间更新statusbar方向属性:(

我不认为这是时间问题。Rob断言设备方向与接口方向不同是正确的。当你将设备平放在桌子上并摇晃桌子时,你可以很明显地看到这种情况。设备方向变化很大,接口方向很可能不会切换。因为有问题的对象它是UIViewController,如果添加到视图控制器层次结构中,它将接收接口旋转事件。为什么要进行所有这些猴子操作?因为对象不是viewController…否则你是对的,这将非常简单;)这是一个叠加的视图。使用此答案,我确实获得了正确的旋转。但是,为了使我的显示更新正确地重新绘制大小,似乎仍然需要延迟。我将测试它,看看它是否有效。我将标记他或我的答案为正确:)