iOS:Add 在 viewController 的导航栏下方查看
iOS:Add view below navigation bar across viewControllers
我有这样一个项目:
但我想弄清楚如何在整个导航栏的导航栏下方添加一个横幅,如果需要的话我可以隐藏它。你们有人知道我该怎么做吗?
在主视图控制器中实现协议 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
上上传了一个示例
希望对您有所帮助
请使用 TSMessages。
这个库提供了一个易于使用的 class 在屏幕顶部显示小的通知视图
对于objective-c,使用RMessage
对于swift,使用SwiftMessages. Preview
我有这样一个项目:
但我想弄清楚如何在整个导航栏的导航栏下方添加一个横幅,如果需要的话我可以隐藏它。你们有人知道我该怎么做吗?
在主视图控制器中实现协议 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
上上传了一个示例希望对您有所帮助
请使用 TSMessages。
这个库提供了一个易于使用的 class 在屏幕顶部显示小的通知视图
对于objective-c,使用RMessage
对于swift,使用SwiftMessages. Preview