如何在UITabBarController-> UINavigationController中的ViewController上获取旋转事件?
问题描述:
无论何时用户将iOS设备从纵向旋转到横向,纵向视图是TabBar和NavigationController内的视图,我都想要显示全屏横向视图。如何在UITabBarController-> UINavigationController中的ViewController上获取旋转事件?
然而,willRotateToInterfaceOrientation:时间:不会被调用。我也测试了将ViewController添加为UIDeviceOrientationDidChangeNotification事件的Observer,但是此通知也以未定义的方向调用。
给定任务的最佳和最简单的方法是什么?
答
也有UIApplicationWillChangeStatusBarOrientationNotification
和UIApplicationDidChangeStatusBarOrientationNotification
通知。
的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]);
}
感谢很好的提示。但是,从不调用UIApplicationWillChangeStatusBarOrientationNotification,因为TabBarController不直接响应方向更改(它只允许纵向),因此状态栏永远不会旋转。 – lambruscoAcido