0

我正在开发一个应用程序,需要隐藏 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 调整了自身的大小(工具栏动画工作得很好。)

关于如何解决这个问题的任何想法?

4

1 回答 1

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 模拟器中对此进行了测试。希望你可以使用它。“黑色矩形”必须是窗口的默认背景颜色,即导航栏和视图之间的间隙。

于 2012-07-30T20:34:58.247 回答