【问题标题】:iOS:Add view below navigation bar across viewControllersiOS:跨视图控制器在导航栏下方添加视图
【发布时间】:2017-01-07 00:49:03
【问题描述】:

我有一个这样的项目:

但我正在尝试弄清楚如何在导航栏下方的导航栏下方添加横幅,以便在需要时将其隐藏。你们有谁知道我该怎么做?

【问题讨论】:

    标签: ios objective-c swift uinavigationcontroller uitabbarcontroller


    【解决方案1】:

    在主视图控制器中实现协议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上传了一个例子

    希望对你有帮助

    【讨论】:

    • 这个实现可以显示在所有的viewControllers中还是只显示在主viewController中?
    【解决方案2】:

    请使用 TSMessages。

    这个库提供了一个易于使用的类来在屏幕顶部显示小的通知视图

    https://github.com/KrauseFx/TSMessages

    【讨论】:

      【解决方案3】:

      对于objective-c,使用RMessage

      要快速,请使用SwiftMessagesPreview

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-19
        • 2012-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多