在我的 Root View Controller 的 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。我不知道为什么会有这种奇怪的行为。如果您知道解决方案,请帮助我。
编辑 同样的代码在我的另一个项目中工作,我找不到它们之间的任何区别
最佳答案
添加这两个方法:
- (BOOL)shouldAutorotate
{
return TRUE;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
并在此处进行所有修改:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration
{
NSLog(@"%f,%f",self.view.frame.size.width,self.view.frame.size.height);
}
关于ios - iPad 中的方向框架不改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18008877/