【问题标题】:UInavigationcontroller Global Alert Message (like WhatsApp incoming message)UInavigationcontroller 全局警报消息(如 WhatsApp 传入消息)
【发布时间】:2013-07-11 17:20:22
【问题描述】:

我正在构建一个应用程序(论坛)并且我有一个 UINavigationController。我想在用户的任何 UIViewController 中显示一条警报消息。我真的不知道该怎么做。

非常感谢您的帮助。

这里有一些我想做的例子: 这是样本

【问题讨论】:

    标签: ios objective-c ios6 uinavigationcontroller alert


    【解决方案1】:

    您可以将此视图添加到keyWindow,并将其置于最前面。 或者你可以把你的alertView做成一个UIWindow,这样你就可以在任何地方显示它了。

    static UIWindow *_sharedNavigationBarAlertView = nil;
    + (UIWindow *)sharedNavigationBarAlertView
    {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            _sharedNavigationBarAlertView = [[UIWindow alloc] initWithFrame:CGRectZero];
            _sharedNavigationBarAlertView.windowLevel = UIWindowLevelStatusBar + 1.0;
            _sharedNavigationBarAlertView.hidden = YES;
            // add other views...
        });
        return _sharedNavigationBarAlertView;
    }
    
    + (void)showWithInformation:(id)info
    {
        // [self sharedNavigationBarAlertView].imageView.image = ...;
        // [self sharedNavigationBarAlertView].titleLabel.text = @"";
        // [self sharedNavigationBarAlertView].detailLabel.text = @"";
        CGRect frame = [UIScreen mainScreen].bounds;
        frame.size.height = 44.0;
        [self sharedNavigationBarAlertView].frame = frame;
        [self sharedNavigationBarAlertView].hidden = NO;
    }
    + (void)hide
    {
        [self sharedNavigationBarAlertView].hidden = YES;
    }
    
    // To release the shared alert window, just set it to nil
    

    【讨论】:

    • 非常感谢!正是我正在搜索的内容
    【解决方案2】:

    UINavigationBarUIView 的子类,所以你可以给它添加子视图。您可以通过任何视图控制器上的navigationController 属性或从您保留UINavigationController 的任何位置访问它。只需添加您的通知子视图并在延迟后将其删除。

    【讨论】:

    • 好的,谢谢!但是如果我不显示 UINavigationBar,我应该在哪里添加子视图?
    • 您可以将其添加为导航控制器视图的子视图,并确保它是前面的子视图。
    猜你喜欢
    • 2013-07-18
    • 2017-03-15
    • 1970-01-01
    • 2015-11-22
    • 2013-01-10
    • 1970-01-01
    • 2020-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多