我有一个这样的项目:
但我试图弄清楚如何在整个导航栏的导航栏下方添加横幅,以便在需要时可以将其隐藏。你们中有人知道我该怎么做吗?
在主视图控制器中实现协议UINavigationControllerDelegate
并在选择器中navigationController:didShowViewController:animated:
您可以操纵导航控制器呈现的视图控制器。例如:
@interface ViewController () <UINavigationControllerDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.delegate = self;
}
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
UIView *banner = [[UIView alloc] initWithFrame:CGRectMake(0, navigationController.navigationBar.frame.size.height + 10,
viewController.view.bounds.size.width,30)];
banner.backgroundColor = [UIColor blueColor];
[viewController.view addSubview:banner];
}
@end
在这个例子中ViewController
应该是第一个呈现的视图控制器UINavigationController
.
我上传了一个例子github https://github.com/FrankFuenmayor/so-ios-simple-banner
希望能帮助到你
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)