首先,在AppDelegate中寫下這個。這是非常IMP
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return (UIInterfaceOrientationMaskAll);
}
那麼,對於UIViewControllers,其中只需要縱向模式,寫這些功能
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait);
}
對於UIViewControllers,需要景觀也變化屏蔽所有。
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskAllButUpsideDown);
//OR return (UIInterfaceOrientationMaskAll);
}
現在,如果您想在方向更改時進行一些更改,請使用此功能。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
}
編輯:
在很大程度上取決於與控制器UIViewController中嵌入
例如,如果其內部的UINavigationController,那麼你可能需要繼承的是UINavigationController的覆蓋方向。像這樣的方法。
subclassed UINavigationController(層次結構的頂級視圖控制器將控制方向。)將它設置爲self.window.rootViewController。
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
從iOS 6中,它被賦予的是UINavigationController的不會要求其UIVIewControllers用於定向支持。因此我們需要對它進行子類化。
試試這個。它爲我工作: http://stackoverflow.com/questions/10096672/uiwindows-root-view-controller-does-not-rotate-to-landscape-at-app-launch –