2012-12-17 93 views
1

我已重写我的UINavigationController实现这些方法:iOS 6的旋转不工作

-(BOOL)shouldAutorotate 
{ 
    return [[self.viewControllers lastObject] shouldAutorotate]; 
} 
-(NSUInteger)supportedInterfaceOrientations 
{ 
    return [[self.viewControllers lastObject] supportedInterfaceOrientations]; 
} 
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
} 
从我的第一视图

现在,我模态呈现这个MSNavigationPaneViewController here这就好比一个Facebook侧滑动标签栏控制器。

我需要在此处显示的我的视图控制器中的1个显示仅在应用视图的其余部分仅为纵向时显示横向。

所以我所有的其他视图控制器我已经加入:

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 
- (BOOL)shouldAutorotate 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

和我想景观一个我已经添加了:

- (BOOL)shouldAutorotate 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 
-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

但是我所有的意见旋转。

如果我在这些其他视图上将shouldRotate更改为NO,那么它们将停留在Portrait中,并且我想成为Landscape的视图可以旋转,但是我无法让它自行旋转。 此外,如果我回到另一个具有shouldRotate = NO;的视图,一旦旋转,则无法将其旋转回肖像。

我已经在这个几个小时了,不能得到它的工作。

感谢

编辑-----

我有这一半现在的工作,并已开始了新的问题,以获得自动旋转工作here

+1

嗯......你的“shouldAutorotate”方法不返回'BOOL's ... –

回答

5

似乎你混淆什么返回在shouldAutorotate。以下面的代码为例。

由于iOS响应来自加速度计的事件向您的应用程序的shouldAutorotate进行调用,因此它已经知道新的方向;如果您的应用程序回答“是”,则iOS可以根据受支持的列表检查当前的方向,然后在没有您的应用程序查询当前方向的情况下提出决定。

// iOS 6的

- (BOOL)shouldAutorotate { 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskPortrait; 
} 

而且,你可以让呈现你的模式视图控制器通知它的旋转视图控制器。使用:presentViewController:animated:completion:显示视图控制器。 presentModalViewController:animated:已被弃用,如果偶然使用它。

如果添加application:supportedInterfaceOrientationsForWindow:,请确保遵循下面的代码准则。该文档指出,如果您在VC上实施supportedInterfaceOrientations,则应覆盖应用程序委托。但是,人们已经注意到,如何将rootViewController添加到主窗口中会有所不同。

用途:代替

window.rootViewController = viewController 

[window addSubview:viewController.view]; 
+0

谢谢,我明天会再次检查一切。 – Darren

+0

谢谢。这很多工作现在,每个视图只能旋转到视图的掩码设置,但我不能获得PreferredOrientation触发,因为我不认为MSNavigationPaneViewController'呈现'每个视图,它只是将它们互换掉。 – Darren

+0

我已经开始了一个关于自动旋转的新问题,我无法工作。 http://stackoverflow.com/questions/13934807/trick-preferredinterfaceorientationforpresentation-to-fire-on-viewcontroller-cha – Darren

1

首先,确保你点击了方向按钮在Xcode让你想要的方向。然后花几个小时搜索iOS 6遇到的所有错误和问题。再花几个小时尝试各种技术。

This post包含一些线索,但远不是最终的话。

特别要注意的是,您现在必须识别“根视图控制器”并将大部分(但不是全部)旋转控件集中在那里,而不是在每个视图控制器中实现它。

+0

谢谢,我会再次审查所有这一切。如果我提出一个模式视图,它是否仍然需要rootView的旋转控件? – Darren

+0

@达伦 - 我不认为任何人都知道iOS 6中的模态视图旋转。 –

+0

@HotLicks我认为唯一的方法就是让呈现模态VC的VC通知它旋转。更新我的答案,提到这一点。 – Bejmax

2

我这样

-(BOOL) shouldAutorotate{ 
    return YES; 
} 

-(NSUInteger) supportedInterfaceOrientations{ 
    if ([self.visibleViewController isKindOfClass:[ZoomPictureViewController class]]) { 
     return UIInterfaceOrientationMaskAll; 
    } 
    return UIInterfaceOrientationMaskPortrait; 
} 

确保您按下了按钮定位在Xcode让你想要的方向和返回supportedInterfaceOrientations方法取向这样做。