0

我在我的应用程序委托中初始化 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 是我的根视图,我可以在它上面添加一个视图吗?或者我只能将视图添加到其子视图控制器之一(左抽屉、中心视图控制器或右抽屉)?

谢谢!

4

1 回答 1

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在一切之上,就在屏幕中间,就好像它完全不知道子视图一样。

于 2014-07-29T01:50:30.627 回答