我以编程方式向我的应用程序添加了一个导航栏,如下所示:
//Setup Navigationbar:
navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 20, [[UIScreen mainScreen ] bounds].size.width, 44)];
UINavigationItem *navigItem = [[UINavigationItem alloc] initWithTitle:@"Navigation Title"];
//Navigationbar left items:
UIButton *fileButton = [UIButton buttonWithType:UIButtonTypeCustom];
[fileButton addTarget:self action:@selector(loadFile:) forControlEvents:UIControlEventTouchUpInside];
[fileButton setImage:[UIImage imageNamed:@"menuicon.png"] forState:UIControlStateNormal];
fileButton.frame = CGRectMake(0, 0, 24, 24);
fileButton.backgroundColor=[UIColor clearColor];
newItem = [[UIBarButtonItem alloc] initWithCustomView:fileButton];
navBar.items = [NSArray arrayWithObjects: navigItem,nil];
//NavigationBar appearance:
[navBar setBackgroundImage:[UIImage imageNamed:@"greenbar.png"] forBarMetrics:UIBarMetricsDefault];
[self.window addSubview: navBar];
[self setTitle:@"Empty"];
问题是我不能让它随着设备旋转,正如你所看到的,我将栏添加到我的 AppDelegate 的窗口中。我如何让它跟随旋转和自动调整大小?