2010-11-18 112 views
9

我有一個ViewController管理一個視圖,我有一個表視圖,一個ImageView和一個導航欄。 當我把它在橫向模式下的導航欄不調整到32時,仍有44 我第一次嘗試使用自動調整大小在IB沒有成功,然後我試圖把這個代碼在視圖控制器風景模式問題與導航欄

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration { 
    //[super willAnimateRotationToInterfaceOrientation:orientation duration:duration]; 
    CGRect frame = self.navigationController.navigationBar.frame; 
    if (UIInterfaceOrientationIsPortrait(orientation)) { 
     frame.size.height = 44; 
    } else { 
     frame.size.height = 32; 
    } 
    self.navigationController.navigationBar.frame = frame; 
} 

但沒有。 我該如何解決這個問題?

回答

7

我犯了一個錯誤,沒有一個navigationController,所以我在代碼與出口掛鉤導航欄導航欄在IB和我使用

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration { 
    [super willAnimateRotationToInterfaceOrientation:orientation duration:duration]; 
    CGRect frame = self.navBar.frame; 
    if (UIInterfaceOrientationIsPortrait(orientation)) { 
     frame.size.height = 44; 
    } else { 
     frame.size.height = 32; 
    } 
    self.navBar.frame = frame; 
} 

它現在,我已經只有圖像視圖的問題

+4

你需要在這個方法中調用super,它不應該被註釋掉。 – titaniumdecoy 2012-03-27 20:41:47

0

我有導航頂部欄的自定義背景圖像相同的問題。

我的風景圖像不是正確的高度,它是44px高而不是32px(@ 2x版本相同,它是88px而不是64)。裁剪完圖像後,風景頂部條具有正確的高度。