我一直在尝试完成同样的事情。我用来执行此操作的方法基于以下概念:
- 高度为 64 磅的背景图像将填充两个
UINavigationBar 和 UIStatusBar。
- 高度为 44 磅的背景图像将填充 UINavigationBar 并离开
UIStatusBar 黑色。
- 您可以在当前 navigationController 的视图顶部添加一个子视图,它将位于 UIStatusBar 下方。
因此,首先,您需要创建两个具有所需 UINavigationBar 外观的图像:
覆盖导航栏和状态栏的 640x128px 图片 (ImageA)
还有一个 640x88px 的图片来覆盖导航栏,但让状态栏保持黑色(ImageB)。
在application:didFinishLaunchingWithOptions:方法中,用ImageA和[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"ImageA.png"] forBarMetrics:UIBarMetricsDefault];设置你的UINavigationBar的背景
当侧边菜单开始打开时,您将需要切换 UINavigationBar 以便它使用 ImageB 并创建一个您将添加到 UIStatusBar 下方的视图。以下是一些示例代码:
// Add a property for your "temporary status bar" view
@property (nonatomic, strong) UIView *temporaryStatusBar;
在侧边菜单开始打开的代码中:
// Create a temporary status bar overlay
self.temporaryStatusBar = [[UIView alloc] initWithFrame:[[UIApplication sharedApplication] statusBarFrame]];
self.temporaryStatusBar.backgroundColor = [UIColor yourColor];
[self.navigationController.view addSubview:self.temporaryStatusBar];
// Update both the current display of the navigationBar and the default appearance values
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"imageB.png"] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"imageB.png"] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setNeedsDisplay];
当侧边菜单动画打开时,或者当用户平移菜单时,您需要做的就是调整 UIStatusBar 叠加层的 alpha 级别。当侧边菜单完全打开时,UINavigationBar 应该有 ImageB 作为其背景图像,并且 UIStatusBar 叠加层的 alpha 应该为 0。当侧边菜单关闭时,您需要替换 UINavigationBar 背景与 ImageA 并删除 UIStatusBar 覆盖。
让我知道这是否适合你!