我有點困惑。 我想我的應用程序正好在我的5個View Controller中的一箇中旋轉。 我創建了一個類別的UINavigationController實現在IOS 6shouldAutorotate沒有被調用,雖然我有類的uinavigationcontroller轉發呼籲
#import "UINavigationController+IOS6Rotation.h"
@implementation UINavigationController (IOS6Rotation)
-(BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if (INTERFACE_IS_PAD) {
return UIInterfaceOrientationLandscapeLeft;
}
else{
return UIInterfaceOrientationPortrait;
}
}
@end
我也有我的所有ViewControllers不應旋轉實現了這些方法旋轉必要的方法。
- (BOOL)shouldAutorotate {
return NO;
}
- (BOOL)supportedInterfaceOrientations {
if (INTERFACE_IS_PAD) {
return UIInterfaceOrientationMaskLandscape;
}
else{
return UIInterfaceOrientationMaskPortrait;
}
}
誰應該轉動;是在shouldAutorotate
啓動時的一個,我使用一個額外的viewController顯示一個閃屏。這個SplashScreen像這樣顯示爲RootViewController。
vc_splash = [[SplashScreenViewController alloc] initWithNibName:@"SplashScreenViewController" bundle:[NSBundle mainBundle]];
[self.window setRootViewController:vc_splash];
DefaultSHKConfigurator *configurator = [[MySHKConfigurator alloc] init];
[SHKConfiguration sharedInstanceWithConfigurator:configurator];
[self.window makeKeyAndVisible];
當我完成加載我的數據庫,splashscreen交換爲主屏幕。
self.viewController = [[MainViewController alloc] initWithNibName:@"MainViewController_iPhone" bundle:nil];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: self.viewController];
[self.window setRootViewController: navControl];
現在的問題是,只有我的飛濺屏幕調用shouldAutorotate,但其他屏幕沒有。 有人可以告訴我,我是否錯過了這裏的一些必需品? 我想我已經做了所有必要的東西來獲取BL ****Ÿ自轉在iOS 6的正常工作......
Thx提前, Maverick1st
**更新* * 如果你希望你的iPad在景觀開始,一定要在你的shouldAutoRotate返回YES,
你爲什麼要實施'UINavigatorController'類別,當你實現了所有的方法,在5'ViewController's的4呢?我認爲實現該類別的目的是爲了避免重複代碼。既然你走了這麼遠,爲什麼不直接在你想旋轉的'ViewController'中直接實現三個旋轉方法呢? – Bill
您需要轉發類別中的方法調用,因爲當viewcontroller包含在tabbarcontroller或navigationcontroller中時,viewcontroller中的方法不會被調用。我已經在選項卡中使用tabbar和navigationcontroller創建了一個應用程序,並且它工作正常。它根本不知道我這次做錯了什麼,因爲它應該在我看來是正確的。 – Maverick1st