我遇到了一些小問題。我試圖開發一個應用程序與UINavigationController欄,但它不旋轉,雖然我的tableView是。 只是一個小小的介紹,所以你知道我的應用程序現在是什麼:我有一個UITableView在IB中創建,並鏈接到我的類ViewController.h和在AppDelegate.h中創建的UINavigationController。 tableView中的所有項目都可以被點擊,它會滑動到另一個viewController,但是這個部分現在不重要。我現在只是試圖在主視圖中支持輪換。UINavigationBar不旋轉
我在AppDelegate.h創建的UINavigationController是這樣的:
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UINavigationController *navigation;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIViewController *viewController;
然後在AppDelegate.m我這樣做:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
return YES;
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
ViewController *viewController = [[ViewController alloc] init];
viewController.title = @"Agrinuvo";
[navigation pushViewController:viewController animated:NO];
navigation = [[UINavigationController alloc] initWithRootViewController:viewController];
navigation.navigationBar.tintColor = [UIColor darkGrayColor];
[[UIBarButtonItem appearance] setTintColor:[UIColor orangeColor]];
[_window addSubview:navigation.view];
}
我在ViewController.m viewDidLoad方法嘗試這些:
self.navigationController.navigationBar.autoresizesSubviews = YES;
self.navigationController.navigationBar.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
我可以調整UINavigationBar,但我不能旋轉它我的生活(仍在ViewController.m):
-(void) orientationChanged
{
CGRect frame = self.navigationController.navigationBar.frame;
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait)
{
self.view.transform = CGAffineTransformMakeRotation(0);
frame.size.height = 44;
frame.origin.y = 15;
}
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown)
{
self.view.transform = CGAffineTransformMakeRotation(M_PI * 1);
frame.size.height = 44;
}
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{
self.view.transform = CGAffineTransformMakeRotation(M_PI * -0.5);
frame.size.height = 32;
}
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft)
{
self.view.transform = CGAffineTransformMakeRotation(M_PI * 0.5);
frame.size.height = 32;
}
self.navigationController.navigationBar.frame = frame;
}
是啊,我也想在我所有的控制器這個方法,它返回是在所有的人,但仍導航欄不旋轉。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
所以我想知道如果它實際上是可以旋轉NavigationBar。我也創建它應該創建它? 我應該以這種方式啓動我的UINavigationController嗎?還是應該在IB中創建它並將其鏈接到.h類?
很抱歉的長閱讀,並感謝您的幫助,您可以提供
爲什麼沒有導航控制器作爲窗口的根視圖控制器?這樣做可能會解決這個問題。 – rdelmar
哇。這實際上做到了...... -.-現在我剩下1個問題了tableview不能正確旋轉。你是否應該從你的評論中作出回答,以便我接受你的回答?或者我應該刪除這個問題? –