用在iPad上

问题描述:

我在一个应用程序帮助了用于iPad上的Xcode 4我知道接口方向有麻烦还有就是用在iPad上

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

如果要支持所有的方向应该返回YES。此前,该应用程序被卡在横向模式。我试图改变观点以支持所有的方向。所以我改变了该方法的出现,以便返回YES而不是只有YES才能用于LandscapeLeft和LandscapeRight方向。但是,当我尝试这样做:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
      NSLog(@"%i, %s", self.interfaceOrientation, __FUNCTION__); 
} 

我总是得到3或4在控制台这是两个横向方向。当您点击项目图标时,我检查了摘要页面,并支持所有设备方向。在.plist文件中,列出所有方向。还有另一个地方,我可以忽略这个设定吗?谢谢。

+0

不知道这是否有用,但它的某处开始 - http://stackoverflow.com/questions/2868132/shouldautorotatetointerfaceorientation-wont-work。 – Perception

+0

听起来好像还有别的东西在这里。尝试聆听全局NSNotification改变方向,然后与您的日志进行比较。 –

我有与呈现子视图控制器的自定义导航控制器一样的问题。在我的例子中,我使用表格视图来呈现网格中的项目,并且我需要我的表格视图单元格根据方向显示不同数量的项目。这里的工作都是围绕我发现:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    // we have to use self.view.window.rootViewController.interfaceOrientation because for some reason 
    // self.interfaceOrientation isn't updating. That's what I get for using custom navigation, I guess. 
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 
    if (!self.isViewLoaded) { 
     return; 
    } 
    if (self.view.window) { 
     if (UIInterfaceOrientationIsPortrait(self.view.window.rootViewController.interfaceOrientation) != UIInterfaceOrientationIsPortrait(fromInterfaceOrientation)) { 
      // if we are rotating between portrait and landscape, we'll have to reload the data 
      [self.tableView reloadData]; 
     } 
    } else { 
     self.needsReloadData = YES; 
    } 
} 

通过读取窗口的根视图控制器的方向,你必须确定设备的实际方位的可靠方法。不幸的是,如果视图控制器的视图已经从当前窗口中删除,self.view.window将返回nil,所以在这种情况下,我必须举起一个标志并在viewDidAppear中处理它。