ios - iPad 中的方向框架不改变

标签 ios objective-c ipad orientation frame

在我的 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/

相关文章:

iphone - 读取 grib2 数据

ios - 视差效果的公式

ios - 苹果是否批准存在内存泄漏的 iOS 应用程序?

ios - 在 UISegmentedControl 上录制点击在测试期间获取断言失败

ios - Objective C 中的@dynamic 属性

iphone - 将 ManagedObjectContext 传递给第二个 View

iphone - localytics 没有给报告?

iphone - 在iPhone中以编程方式发送短信

ios - 如何继承具有 .xib 文件的自定义 View

ios - Objective-C 中的调用方法层次结构