2013-03-04 46 views
1

我有一个应用程序,其中包含5.0作为部署目标,6.1作为基本sdk,并且它在iOS 6.x设备/模拟器上运行良好。但在5.x上,我的观点不是在旋转。我搜索了一下,发现了一些Stackoverflow的帖子,但我不能找到正面和反面的一切。我想我需要实现我自己使用的不同视图控制器的子类,但是哪一个是对的?为什么iOS 5的轮换在iOS 6下工作不起作用

在我的应用程序委托didFinishLaunchingWithOptions我使用它来创建我的应用程序:

self.tabBarController = [[UITabBarController alloc] init]; 
self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3]; 
self.window.rootViewController = self.tabBarController; 
[self.window makeKeyAndVisible]; 

创建我viewController1 ..这样的:

viewController1 = [[UINavigationController alloc] initWithRootViewController:[[SearchVC alloc] initWithNibName:@"SearchVC_iPhone" bundle:nil]]; 

我试图在我的SearchVC_iPhone视图控制器实现shouldAutorotateToInterfaceOrientation我已经尝试在子类中继承UINavigationController并实现shouldAutorotateToInterfaceOrientation,但它不适合我,我真的只是在这里猜测。

请任何人都知道这个东西帮助我在这里,我需要做什么才能让这个工作在iOS 5.x也?

谢谢
瑟伦

回答

1

我解决了它!问题是rootViewController,我必须在rootViewController上实现shouldAutorotateToInterfaceOrientation,然后所有子视图开始按照他们应该的方式工作。所以我做了我自己的UITabBarController子类,它实现了shouldAutorotateToInterfaceOrientation并将其设置为rootViewController。

+0

请设置你的问题。 – dhcdht 2013-03-04 11:49:07

2

在IOS5你可以使用

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    return YES; 
} 

在iOS6的,你可以使用

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskAll; 
} 
+0

是的我试着在我的视图控制器中实现shouldAutorotateToInterfaceOrientation,但我的视图仍然不会在iOS 5.x中旋转 – Neigaard 2013-03-04 10:03:58

0

我工作的一个应用程序(的Xcode 4.5的iOS 6) ,它必须与已安装软件版本的设备兼容,从4.5开始并默认使用iPhone 5.

我知道新的iOS 6更改自动旋转模式。

当你打开你的设备“iPhone Simulator 6.0”应用程序的行为正常,但当我在旋转的方式运行“iPhone模拟器5.0”的问题。

我把代码,以及从iOS 6和旧方法(不推荐)旋转到iOS 5的新方法。

所以找旋转方法:

{

if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) 

{ 

    //Code Here 

} 


if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) 

{ 

    //Code Here 

} 

return YES; 

}

#pragma mark - Rotate Methods iOS 6 
  • (无效)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 持续时间:(NSTimeInterval)持续时间

    {

如果(UIInterfaceOrientationIsPortrait(toInterfaceOrientation))

{ 

     //Code here 

    } 

如果(UIInterfaceOrientationIsLandscape(toInterfaceOrientation))

{ 

     //Code here 

    } 

}

相关问题