shouldAutorotate不会被调用

问题描述:

我想这取决于用户在哪里我的应用程序支持的方向来定义,我有一个非常困难的时期这样做。shouldAutorotate不会被调用

到目前为止,我已经发现我应该使用iOS6中现在支持的supportedInterfaceOrientationsForWindow:和shouldAutorotate方法,但是无论哪种方法在我的UIViewController中定义它们时都不会调用。

这是我的代码是什么样子

- (BOOL)shouldAutorotate { 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientationsForWindow { 
    return UIInterfaceOrientationMaskPortrait; 
} 

在我的目标概要支持Orientatoin我已经取消选择所有选项..想,我只想在每个m ViewControllers的定义支持的方向...我会想知道这是否是正确的事情?

enter image description here

现在我已经读什么,我试图做的是依赖于我的应用程序的药结构,所以在这里,我将概述我的应用程序。

  • 主要的UIViewController(3个按钮带你到(3个不同的navigationControllerViews)错了!只有一个navigationController ......对不起它以来我看着这个代码很长一段时间。)
  • 次要的UIViewController(持有导航控制器)
  • 其他UIViewControllers(出现在secondarys NavigationController)

我想每一个的ViewController起来,直到最后一个在NavigationController堆出现在portrate。 NavigationController中的最后一个视图是一个特殊的视图,需要时可以将其方向旋转到左侧或右侧。

我想知道这是可能的,如果是这样,为什么心不是我有上面的工作代码/被调用。

任何帮助将不胜感激。

//更新质疑回复:

RootView负载与(三个按钮,这里是当选择一个按钮,被称为加载包含导航控制器视图的方法)

- (IBAction)buttonClick: (UIButton *) sender 
{ 
//.. 

    // v -----> 
    if ([sender isEqual:vUIButton]) { 


     VSearchViewController *vSearchViewController = [[VSearchViewController alloc] initWithNibName:@"VSearchViewController" bundle:nil]; 
     [self.navigationController pushViewController:vehicalSearchViewController animated:YES]; 
    } 
//.. 
} 

然后里面VSearchViewController我加载到UINavigation堆栈这样

//.. 
FModelsViewController *fModelsViewController = [[FModelsViewController alloc] initWithNibName:@"FModelsViewController" bundle:nil]; 

      // Sets the back button for the new view that loads (this overrides the usual parentview name with "Back") 
      self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil]; 

      [self.navigationController pushViewController:fModelsViewController animated:YES]; 
//.. 

所以在检讨,我已经设置了导航控制器的新观点在的appDelegate和我的应用程序的所有意见都在navigationStack ......我错在说有3个NavigationControllers ..只有一个,每个视图添加到堆栈..我们对此深感抱歉..它已经有一年因为我看着这个代码半..

是否运行在iOS6的上面的代码?这些方法只能在iOS6上调用。

而且也许你可以张贴一些代码来更好地说明你是如何过渡到这些viewControllers所以我们可以更好地了解视图层次结构。

你可能想看看UIViewController的addChildViewController:方法。

+0

没关系,我会后的过渡代码..我的应用程序正在变成升技兽的不少意见,由于我想代表数据的复杂性。我会在几分钟内更新我的问题..我会尽我所能提供您需要的信息。 (是,我正在部署到iOS6,它在“目标”>“iosApplication目标”>“部署目标”中正确定义?)。 – HurkNburkS 2013-03-13 21:40:57

+0

你需要确保你在ios6模拟器上运行它。仅仅因为你的部署目标是6并不意味着你在6上运行它。 – 2013-03-13 21:44:24

+0

是我在我的ios6设备上运行。另外我已经更新了一些代码。 – HurkNburkS 2013-03-13 22:03:02

我认为你最后的观点可以采取下面写的代码的优势。它会感应设备的方向,并会为横向视图显示不同的视图控制器(我假设这是您正在尝试执行的操作)。这意味着你的最后一个视图将有一个肖像和一个风景选项。

@implementation LastViewController 

- (void)awakeFromNib 
{ 
isShowingLandscapeView = NO; 
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
[[NSNotificationCenter defaultCenter] addObserver:self 
         selector:@selector(orientationLastViewChanged:) 
         name:UIDeviceOrientationDidChangeNotification 
         object:nil]; 
} 
- (void)orientationLastViewChanged:(NSNotification *)notification 
{ 

UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; 
if (UIDeviceOrientationIsLandscape(deviceOrientation) && 
!isShowingLandscapeView) 
{ 
[self performSegueWithIdentifier:@"LandscapeLastView" sender:self]; 
isShowingLandscapeView = YES; 
} 
else if (UIDeviceOrientationIsPortrait(deviceOrientation) && 
    isShowingLandscapeView) 
{ 
[self dismissViewControllerAnimated:YES completion:nil]; 
isShowingLandscapeView = NO; 

} 

} 
在视图控制器导致这一观点,即你想锁定肖像

,写这样的代码:

- (BOOL)shouldAutorotate { 
return NO; 
} 

为您支持的接口方向,离开你如何拥有它。

+0

那么你说的最后一个视图会有不同的.xib文件?那是对的吗? – HurkNburkS 2013-03-13 22:05:48

+0

是的,但实际上我的答案假设你正在使用故事板。注意performSegueWithIndetifier方法。这是在故事板中完成的。你最后一个视图需要2个不同的视图控制器(一个是纵向,一个是横向)。你会有一个连接肖像与景观的连线,另一个连接景观与肖像。 – iOSAppGuy 2013-03-13 22:30:37

+0

right ..不幸的是,这种方法不会为我工作(我知道自私的权利!大声笑)..我的最后一个看法是如此错综复杂,我想这将是几乎不可能得到这个工作内部允许我不允许重写视图...但是非常感谢你的回答,如果结果证明它是实现我所追求的结果的唯一方法,我会更多地考虑它。 – HurkNburkS 2013-03-13 22:38:24