每当用户将iOS设备从纵向旋转到横向时,我想显示全屏横向视图,其中纵向视图是TabBar和NavigationController中的视图。
然而,willRotateToInterfaceOrientation:duration:永远不会被调用。我还测试了将ViewController添加为UIDeviceOrientationDidChangeNotification事件的Observer,但是这个通知也是以未定义的方向调用的。
给定任务的最佳和最简单方法是什么?
答案 0 :(得分:1)
还有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]);
}