切换到 iOS5,我想使用UINavigationBar
使用以下代码片段的自定义样式:
if ([navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:
forBarMetrics:)]) {
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavigationBar.png"]
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavigationBarLandscape.png"]
forBarMetrics:UIBarMetricsLandscapePhone];
}
这很好用,但是:我的自定义图像有圆角(参见附加图像),导致以下情况:
从纵向模式开始,它看起来很好。
更改为横向模式看起来也不错。
然而,改回纵向模式似乎不会将图像更改为NavigationBar.png,因此右上角没有圆角。
任何有关如何解决此问题的建议表示赞赏。
// 编辑
将以下代码添加到我的 viewController 会删除此“错误”,但这不是正确的解决方案!?!
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation
duration:duration];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"NavigationBar.png"]
forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"NavigationBarLandscape.png"]
forBarMetrics:UIBarMetricsLandscapePhone];
}