简体   繁体   中英

How to add an UIView to the front most view of the whole iOS in the tweak application?

My app is a tweak app running in SpringBoard , in which I want to use MBProgressHUD , but it need to specify a view to add to, so how can I get the font most view of the whole iOS ?

I should do like that:

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:fronMostView animated:YES];
hud.mode = MBProgressHUDModeText;
hud.labelText = [Localization localize:@"Finished!"];
[hud hide:YES afterDelay:1];

The best place to add this view is AppDelegate . Add view in to appDelegate window will show to top front for whole application. Also it remains on top until you hide or remove this view from appDelegate window.

Create a global object of MBProgressHUD in AppDelegate class and create show/hide methods.

Call this methods respectively for your convenience use.

For Example:

@property (nonatomic, strong)  MBProgressHUD   *hud;

- (void) showProgress:(NSString *)message {

    // Create a loading view
    if (!self.hud) {
        _hud = [MBProgressHUD showHUDAddedTo:fronMostView animated:YES];
        self.hud.mode = MBProgressHUDModeText;

        // Add Progress to window.
       [self.window addSubview:self.hud];
    }

    self.hud.hidden = NO;
    self.hud.labelText = [Localization localize:message];
}


- (void) hideLoadingMessage {
    self.hud.labelText = [Localization localize:@"Finished!"];
    [self.hud hide:YES afterDelay:1];
}

try

UIWindow* window = [[UIApplication sharedApplication] keyWindow];

or

UIWindow *window = [UIApplication sharedApplication].windows.lastObject;

Then

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];

Here is a topic about this , maybe it'll be useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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