iOS 6与导航控制器的方向

时间:2012-10-31 14:32:43

标签: objective-c xcode uinavigationcontroller ios6 uideviceorientation

我有一个适用于ios 5的应用程序,即时尝试升级我的应用程序以在ios 6上工作,我已经阅读了大量关于使用ios 6方向的问题和教程,

我的问题是,当我调用我的rootViewController它与我工作正常,但当我推动任何viewController时,方向看起来很糟糕,因为我使用方向来更改视图大小(我的应用程序支持任何方向)

这是我的代码:

AppDelegate:


UINavigationController *nav =[ [UINavigationController alloc] initWithRootViewController:theView]  ;
self.window.rootViewController = nav;


- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window  // iOS 6
{

return UIInterfaceOrientationMaskAll;


}




myFirstViewController:

-(NSUInteger)supportedInterfaceOrientations{

return UIInterfaceOrientationMaskAll;
 }

 -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

    [self viewWillAppear:NO];
 }

 -(BOOL)shouldAutorotate{
 return YES;
  }

- (void)viewWillAppear:(BOOL)animated
{

[super viewWillAppear:NO];
if ( [[UIDevice currentDevice].systemVersion floatValue] >= 6.0){
    if (pointRange.location != NSNotFound) {



UIInterfaceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];

if( (interfaceOrientation >= 3)  ) {
     width=1024;
    self.view.frame=CGRectMake(0, 0, 1024, 768);

}


if   ( (interfaceOrientation == 1) || (interfaceOrientation == 2 )) {

    width=768;
    self.view.frame=CGRectMake(0, 0, 768, 1024);


}}
....etc

我在第二种观点中做了同样的事情,希望找到原因!!

2 个答案:

答案 0 :(得分:1)

您可以像这样

对UINavigationController进行扩展
@implementation UINavigationController (RotationFix)

-(NSUInteger)supportedInterfaceOrientations
{
    return [self.topViewController supportedInterfaceOrientations];
}

-(BOOL)shouldAutorotate
{
    return YES;
}

@end

答案 1 :(得分:0)

即使我遭受了2天的困扰..经历过许多教程,博客,论坛,甚至苹果文档。

到目前为止,我才知道,在iOS 6中,应用程序的每个模板都应以不同的方式处理。

到目前为止,讨论仅针对基于视图的应用,并且这些更改不适用于基于导航的应用或基于tabBar的应用。

最后我得到了解决方案,就像这样

实施这两种类型的子类UITabBarControllerUINavigationController

从此blog了解到。感谢Shabbir的解决方案。