【发布时间】:2016-05-04 11:39:55
【问题描述】:
我正在尝试创建一个透明的UINavigationBar,这就是我所做的:
首先,我的代码中有一个 navVC 和一个通用 VC 作为根 VC。
SNLoginViewController *loginVC = [[SNLoginViewController alloc] init];
SNLoginNavController *loginNavVC = [[SNLoginNavController alloc] initWithRootViewController:loginVC];
[self presentViewController:loginNavVC animated:YES completion:nil];
我没有覆盖SNLoginViewController 的init 方法。
这里是initWithRootViewController:的实现:
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController {
self = [super initWithRootViewController:rootViewController];
if (self) {
UIImage *bgImage = [UIImage imageNamed:@"bg"];
UIImageView *bgImageView = [[UIImageView alloc] initWithImage:bgImage];
bgImageView.frame = [UIScreen mainScreen].bounds;
[self.view insertSubview:bgImageView atIndex:0];
[self.navigationBar setBackgroundImage:[UIImage imageNamed:@"transparent"]//transparent is a transparent png
forBarMetrics:UIBarMetricsCompact];
self.navigationBar.shadowImage = [UIImage imageNamed:@"transparent"];
self.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName: [UIFont systemFontOfSize:18]}];
self.navigationBar.clipsToBounds = YES;
}
return self;
}
使用这些代码 (setBackgroundImage:forBarMetrics:) 我应该能够使导航栏透明,但出现了问题。主要问题是loginVC 的框架不知何故小于loginNavVC。
(来源:zybuluo.com)
在上图中,选中的视图是loginVC,左边的视图是loginNavVc。 loginVC 小于 loginNavVc。
但是在loginVC 的viewDidLoad 中,我打印选定的视图,它的框架是(0 0; 320 568)但是当我在视图层次结构中打印它的描述(内存中的相同地址)时,它的框架是(0 64 ; 320 504)。为什么会发生这种情况?如何让它全屏(不是像游戏一样全屏,状态栏应该仍然可见)?
【问题讨论】:
-
在故事板中选择了哪些选项来调整滚动和延伸边缘?
标签: ios objective-c uinavigationcontroller uinavigationbar