如何在UITabBarController-> UINavigationController中的ViewController上获取Rotation事件?

时间:2011-11-10 13:22:04

标签: iphone uinavigationcontroller uitabbarcontroller rotation uiinterfaceorientation

每当用户将iOS设备从纵向旋转到横向时,我想显示全屏横向视图,其中纵向视图是TabBar和NavigationController中的视图。

然而,willRotateToInterfaceOrientation:duration:永远不会被调用。我还测试了将ViewController添加为UIDeviceOrientationDidChangeNotification事件的Observer,但是这个通知也是以未定义的方向调用的。

给定任务的最佳和最简单方法是什么?

1 个答案:

答案 0 :(得分:1)

还有UIApplicationWillChangeStatusBarOrientationNotificationUIApplicationDidChangeStatusBarOrientationNotification次通知。

userInfo字典包含一个封装UIInterfaceOrientation值的NSNumber对象。使用UIApplicationStatusBarOrientationUserInfoKey访问此值

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

- (void) didRotate:(NSNotification *)notification{   
    NSNumber *num = [[notification userInfo] objectForKey:@"UIApplicationStatusBarOrientationUserInfoKey"];
    NSLog(@"%d", [num intValue]);
}