iOS:Add view below navigation bar across viewControllers

可紊 提交于 2019-12-13 16:16:46

问题


I have a project like this:

But I'm trying to figure out how to add a banner below the navigation bar across the navigation bar in a way where can I hide it if is need it. Any of you knows how can I do this?


回答1:


plz use TSMessages.

This library provides an easy to use class to show little notification views on the top of the screen

https://github.com/KrauseFx/TSMessages




回答2:


In the main view controller implement the protocol UINavigationControllerDelegate and in the selector navigationController:didShowViewController:animated: you can manipulate the view controller presented by the navigation controller. e.g:

@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

In this example ViewController should be the first view controller presented for the UINavigationController.

I uploaded an example on github

Hope it helps




回答3:


for objective-c, use RMessage

for swift, use SwiftMessages. Preview



来源:https://stackoverflow.com/questions/39232497/iosadd-view-below-navigation-bar-across-viewcontrollers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!