简体   繁体   English

我可以在iPhone上使用一个简单的开源HUD(类似于MBProgressHUD)吗?

[英]Is there a simple open source HUD (similar to MBProgressHUD) that I can use on IPhone?

I don't want to use MBProgressHUD because of the overhead for threads and managing background asks. 由于线程和管理后台请求的开销,我不想使用MBProgressHUD。 I don't need a background task handler. 我不需要后台任务处理程序。 Just a simple, thread safe library that deals with views/windows should do the job. 只需处理视图/窗口的简单,线程安全的库即可完成此工作。 Also without creating an instance from different view controllers and adding/removing it, I think its too much work for the consumer. 同样,如果没有从其他视图控制器创建实例并添加/删除实例,我认为对于使用者而言,它的工作量太大。 I should be able to call it from anywhere in the code. 我应该可以在代码中的任何地方调用它。 Something like this: 像这样:
[SimpleHud getInstance] pop];
[SimpleHud getInstance] pop withTitle:@"Doing stuff"];
[SimpleHud getInstanca] hide];

I like David Sinclair's DSActivityView . 我喜欢David Sinclair的DSActivityView It's lighter than MBProgressHUD, though not featherweight. 它比MBProgressHUD轻,尽管不轻巧。 Worth taking a look. 值得一看。

This is what I come up with: 这是我想出的:

   -(void)pop:(NSString *)text {
        [self performSelectorOnMainThread:@selector(popLightBox:) withObject:text waitUntilDone:YES];
    }

    -(void)hide {
        [self performSelectorOnMainThread:@selector(hideLightBox) withObject:nil waitUntilDone:YES];
    }

    -(void)popLightBox:(NSString *)text
    {
        NSArray *windows =  [[UIApplication sharedApplication] windows];    
        NSInteger last = [windows count]-1;
        if (last < 0) return;
        UIWindow *currentWindow = [windows objectAtIndex:last];
        [currentWindow addSubview:self.view];
        if (text == nil) {
            self.loadingLabel.text = __DEFAULT_LOADING_TEXT__;      
        }else {
            self.loadingLabel.text = text;
        }
    }

    -(void)hideLightBox
    {
        [self.view removeFromSuperview];
    }

Class is a simple UIViewController. 类是一个简单的UIViewController。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM