【问题标题】:Putting a View on Top of MMDrawerController在 MMDrawerController 上放置一个视图
【发布时间】:2014-07-29 09:50:30
【问题描述】:

我正在我的应用程序委托中初始化 MMDrawerController,如下所示:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController *menu = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:@"menu"];
UINavigationController *center = (UINavigationController *)[storyboard instantiateViewControllerWithIdentifier:@"center"];

self.drawerController = [[MMDrawerController alloc]
                       initWithCenterViewController:center
                       leftDrawerViewController:menu
                       rightDrawerViewController:nil];

然后我将我的根视图控制器设置为 MMDrawerController,如下所示:

[self.window setRootViewController:self.drawerController];

我希望能够在视图中覆盖 UIActivityIndicator 覆盖 MMDrawerController 内部发生的所有事情,这样我就可以在某些操作完成时以全局方式使 UI 不可用。

如果 MMDrawerController 是我的根视图,我可以在它上面添加一个视图吗?或者我只能将视图添加到其子视图控制器之一(左抽屉、中心视图控制器或右抽屉)?

谢谢!

【问题讨论】:

    标签: ios objective-c mmdrawercontroller


    【解决方案1】:

    ProgressHUD cocoapod 源提供了有关如何执行此 IMO 的提示。基本上,它将进度视图添加到窗口本身。

    - (id)init
    {
    self = [super initWithFrame:[[UIScreen mainScreen] bounds]];
    
    id<UIApplicationDelegate> delegate = [[UIApplication sharedApplication] delegate];
    
    if ([delegate respondsToSelector:@selector(window)])
        window = [delegate performSelector:@selector(window)];
    else window = [[UIApplication sharedApplication] keyWindow];
    
    //...
    
    - (void)hudCreate //called as part of the [ProgressHUD show] method
    {
    // ...
    
    if (hud == nil)
    {
        hud = [[UIToolbar alloc] initWithFrame:CGRectZero];
        hud.translucent = YES;
        hud.backgroundColor = HUD_BACKGROUND_COLOR;
        hud.layer.cornerRadius = 10;
        hud.layer.masksToBounds = YES;
    
    }
    //...
    
    if (hud.superview == nil)
    {
        if (interaction == NO)
        {
            CGRect frame = CGRectMake(window.frame.origin.x, window.frame.origin.y, window.frame.size.width, window.frame.size.height);
            background = [[UIView alloc] initWithFrame:frame];
            background.backgroundColor = [UIColor clearColor];
            [window addSubview:background];
            [background addSubview:hud];
        }
        else [window addSubview:hud];
    }
    
    //...
    }
    

    我尝试在左侧抽屉打开时显示 ProgressHUD,因此它显示了左侧抽屉视图的一部分和中心视图的一部分。果然,HUD在一切之上,就在屏幕中间,就好像它完全不知道子视图一样。

    【讨论】:

    • ProgressHUD 看起来正是我所需要的。无需从头开始。感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2013-06-01
    相关资源
    最近更新 更多