2013-06-02 44 views
0

我已編程方式添加的導航欄,以我的應用程序如下:如何使導航欄旋轉與設備

//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"]; 

問題是我不能讓它與設備轉動,正如你所看到的IM增加酒吧到我的AppDelegate的窗戶。我如何使它跟隨旋轉和自動調整大小?

回答

0

要啓用導航欄的旋轉功能,需要將其添加到對設備旋轉有反應的視圖中。我通過從[self.window addSubview: navBar];切換到[self.window.rootViewController.view addSubview: navBar];