我正在这样在我的应用程序委托中初始化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];
我希望能够将MMDrawerController内部所有视图的
UIActivityIndicator
覆盖在视图的顶部,以便在某些操作完成时可以采用全局方式使UI不可用。如果MMDrawerController是我的根视图,是否可以在其顶部添加视图?还是只能将视图添加到其子视图控制器之一(左抽屉,中央视图控制器或右抽屉)?
谢谢!
最佳答案
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位于屏幕中间,位于所有内容的顶部,好像它完全不了解子视图。