在我的根视图控制器的 viewDidLoad 中,我添加了一个用于方向检测的观察者:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willRotateToInterfaceOrientation:duration:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
添加了如下方法:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
NSLog(@"%f,%f",self.view.frame.size.width,self.view.frame.size.height);
}
我期待纵向的结果为 768,1004,横向的结果为 1004,768。但我的结果是两者都是 768,1004。有时,肖像会是 748,1024。我不知道为什么会出现这种奇怪的行为。如果您知道解决方案,请帮助我。
编辑 这个相同的代码在我的另一个项目中工作,我找不到它们之间的任何区别