【发布时间】:2014-03-22 12:51:25
【问题描述】:
我希望将图像的矩形 (0, 0, 320, 64) 作为 UINavigationController 的 UINavigationBar 的背景,并将图像的其余部分作为 UIViewController 视图的背景。 UINavigationController 的 UINavigationBar 背景不应该是透明的。 因此,当用户向上滚动视图时,它应该位于 UINavigationBar 下方。
我已经通过以下方式解决了这个问题:
-
在我的自定义 UINavgationController 类的初始化中:
UIImage *backgroundTopRect = [UIImage imageNamed:@"backgroundTopRect"]; [self.navigationBar setBackgroundImage:backgroundTopRect forBarMetrics:UIBarMetricsDefault]; UIImage *backgroundRestRect = [UIImage imageNamed:@"backgroundRestRect"]; [self.view setBackgroundColor:[UIColor colorWithPatternImage:backgroundRestRect]]; -
在每个 UIViewController 的类的 viewDidLoad 中:
[self.view setBackgroundColor:[UIColor clearColor]];
在 pushViewController:animated: 动画之后只移动文本。例如,如果一个 UIViewController 包含多行 UILabel 并且 push 一个也包含多行 UILabel 并且两者的背景都是透明的,则交叉溶解动画将仅适用于 UILabel 的文本。 看起来很糟糕。
所以我决定在
的帮助下替换默认动画 -(id<UIViewControllerAnimatedTransitioning>) navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
问题是我说的对吗?还是有另一种正确的方法来达到我想要的?
【问题讨论】:
标签: ios ios7 background uinavigationbar