2012-04-30 49 views
0

我正在研究一個應用程序,並且需要隱藏UINavigationBar(和工具欄)以在應用內瀏覽器中提供全屏模式。默認iOS UINavigationBar動畫不平滑

當應用程序運行此代碼時,動畫工作得很好。

[self.navigationController setNavigationBarHidden:YES animated:YES]; 
[self.navigationController setToolbarHidden:YES animated:YES]; 

當我想退出全屏模式時,動畫根本不流暢。

[self.navigationController setNavigationBarHidden:NO animated:YES]; 
[self.navigationController setToolbarHidden:NO animated:YES]; 

在動畫黑色矩形是導航欄下看到,我認爲這是調整本身的UIWebView(工具欄動畫作品就好了。)

我如何能解決這個問題的任何想法問題?

+0

你有沒有找到解決這個問題的解決方案? –

+0

@nessup nope,還沒有。 – Francesco

回答

1

而不是使用setNavigationBarHidden:animated:隱藏導航欄,試試這個:

在您的視圖控制器的viewDidLoad計算不同的幀爲您導航欄和您的看法:

// The normal navigation bar frame, i.e. fully visible 
normalNavBarFrame = self.navigationController.navigationBar.frame; 

// The frame of the hidden navigation bar (moved up by its height) 
hiddenNavBarFrame = normalNavBarFrame; 
hiddenNavBarFrame.origin.y -= CGRectGetHeight(normalNavBarFrame); 

// The frame of your view as specified in the nib file 
normalViewFrame = self.view.frame; 

// The frame of your view moved up by the height of the navigation bar 
// and increased in height by the same amount 
fullViewFrame = normalViewFrame; 
fullViewFrame.origin.y -= CGRectGetHeight(normalNavBarFrame); 
fullViewFrame.size.height += CGRectGetHeight(normalNavBarFrame); 

當你想要去的全屏:

[UIView animateWithDuration:0.3 
        animations:^{ 
         self.navigationController.navigationBar.frame = hiddenNavBarFrame; 
         self.view.frame = fullViewFrame; 
        } completion:^(BOOL finished) { 

        }]; 

當你想恢復到正常:

[UIView animateWithDuration:0.3 
        animations:^{ 
         self.navigationController.navigationBar.frame = normalNavBarFrame; 
         self.view.frame = normalViewFrame; 
        } completion:^(BOOL finished) { 

        }]; 

在iOS 5.1仿真器中進行了測試。希望你能使用它。 「黑色矩形」必須是窗口的默認背景顏色,即導航欄和視圖之間的間隙。