Show a view over the keyboard
Asked Answered
A

3

6

I am looking for a way on the iPhone, due to a custom 'loading' subview, to have a subview cover the keyboard without dismissing the keyboard. Right now when the subview loads, the keyboard is still topmost. Any ideas?

Aymara answered 1/7, 2011 at 5:44 Comment(1)
Whenever You are adding subview to the current View just write this code before adding subview [TextView resignFirstResponder]; as you are opening keyboard from UITextView.Epigraphic
D
7

add your loading view as subview on window. It will cover keyboard too. Here is a stackoverflow post for the same

IPhone - Show Wait Indicator

UPDATE

My code

#pragma mark -
#pragma mark Waiting View
- (void)showWaitingView {

    CGRect frame = CGRectMake(90, 190, 32, 32);
    UIActivityIndicatorView* progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame];
    [progressInd startAnimating];
    progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;

    frame = CGRectMake(130, 193, 140, 30);
    UILabel *waitingLable = [[UILabel alloc] initWithFrame:frame];
    waitingLable.text = @"Processing...";
    waitingLable.textColor = [UIColor whiteColor];
    waitingLable.font = [UIFont systemFontOfSize:20];;
    waitingLable.backgroundColor = [UIColor clearColor];
    frame = [[UIScreen mainScreen] applicationFrame];
    UIView *theView = [[UIView alloc] initWithFrame:frame];
    theView.backgroundColor = [UIColor blackColor];
    theView.alpha = 0.7;
    theView.tag = 999;
    [theView addSubview:progressInd];
    [theView addSubview:waitingLable];

    [progressInd release];
    [waitingLable release];

    [window addSubview:[theView autorelease]];
    [window bringSubviewToFront:theView];
}

- (void)removeWaitingView {
    UIView *v = [window viewWithTag:999];
    if(v) [v removeFromSuperview];

}
Deva answered 1/7, 2011 at 5:45 Comment(7)
Thanks for the link. Actually MBProgressHUD is what I am trying to implement. however, I want the keyboard to always remain visible and MBProgressHUD is behind the keyboard.Aymara
@Jake Sankey You can add mbprogresshud to window instead of current view.I'm posting a simple code to display a activity indicator. You can use that.Deva
there is no 'window' in my implementation file. it is in the app delegate. i tried [super.view.window addSubview:HUD]; with no luck ...Aymara
you have window in applicationDelegate. From app delegate you need to call this function.Deva
I'm sorry Rahul, I don't understand what you mean. What function am I calling? I am trying to load the MBProgressHUD over my viewcontroller so the appdelegate (which defines 'window') doesn't seem accessible.Aymara
you can access appDelegate anywhere in the application using the below code yourAppdelegateName *appDelegate = [UIApplication sharedApplication].delegate; By the way the code I have posted you need to paste into your appDelegate class. And then access like this. yourAppdelegateName *appDelegate = [UIApplication sharedApplication].delegate; //To display waiting View [appDelegate showWaitingView]; //To remove Waiting View [appDelegate removeWaitingView];Deva
this doesn't seem to work with the iOS5 SDK. The keyboard is on top no matter what.Chalet
C
19
@interface UIApplication (Util)

- (void)addSubViewOnFrontWindow:(UIView *)view;

@end

@implementation UIApplication (Util)

- (void)addSubViewOnFrontWindow:(UIView *)view {
    int count = [self.windows count];
    UIWindow *w = [self.windows objectAtIndex:count - 1];
    [w addSubview:view];
}

@end


UIApplication *app = [UIApplication sharedApplication];
[app addSubViewOnFrontWindow:_loadingView];
Charleen answered 8/12, 2011 at 3:22 Comment(2)
great! when keyboard is appeared - count will be 2Unilocular
Just add the view to [UIApplication sharedApplication].windows.lastObject also work, thanks.Cesarean
A
13
UIWindow *window = [UIApplication sharedApplication].windows.lastObject;
[window addSubview:self.view];                                                                                                                                                                                                                                        
[window bringSubviewToFront:self.view];
Avilla answered 2/6, 2014 at 17:33 Comment(1)
how can we get front the UIPopoverController to front?Generic
D
7

add your loading view as subview on window. It will cover keyboard too. Here is a stackoverflow post for the same

IPhone - Show Wait Indicator

UPDATE

My code

#pragma mark -
#pragma mark Waiting View
- (void)showWaitingView {

    CGRect frame = CGRectMake(90, 190, 32, 32);
    UIActivityIndicatorView* progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame];
    [progressInd startAnimating];
    progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;

    frame = CGRectMake(130, 193, 140, 30);
    UILabel *waitingLable = [[UILabel alloc] initWithFrame:frame];
    waitingLable.text = @"Processing...";
    waitingLable.textColor = [UIColor whiteColor];
    waitingLable.font = [UIFont systemFontOfSize:20];;
    waitingLable.backgroundColor = [UIColor clearColor];
    frame = [[UIScreen mainScreen] applicationFrame];
    UIView *theView = [[UIView alloc] initWithFrame:frame];
    theView.backgroundColor = [UIColor blackColor];
    theView.alpha = 0.7;
    theView.tag = 999;
    [theView addSubview:progressInd];
    [theView addSubview:waitingLable];

    [progressInd release];
    [waitingLable release];

    [window addSubview:[theView autorelease]];
    [window bringSubviewToFront:theView];
}

- (void)removeWaitingView {
    UIView *v = [window viewWithTag:999];
    if(v) [v removeFromSuperview];

}
Deva answered 1/7, 2011 at 5:45 Comment(7)
Thanks for the link. Actually MBProgressHUD is what I am trying to implement. however, I want the keyboard to always remain visible and MBProgressHUD is behind the keyboard.Aymara
@Jake Sankey You can add mbprogresshud to window instead of current view.I'm posting a simple code to display a activity indicator. You can use that.Deva
there is no 'window' in my implementation file. it is in the app delegate. i tried [super.view.window addSubview:HUD]; with no luck ...Aymara
you have window in applicationDelegate. From app delegate you need to call this function.Deva
I'm sorry Rahul, I don't understand what you mean. What function am I calling? I am trying to load the MBProgressHUD over my viewcontroller so the appdelegate (which defines 'window') doesn't seem accessible.Aymara
you can access appDelegate anywhere in the application using the below code yourAppdelegateName *appDelegate = [UIApplication sharedApplication].delegate; By the way the code I have posted you need to paste into your appDelegate class. And then access like this. yourAppdelegateName *appDelegate = [UIApplication sharedApplication].delegate; //To display waiting View [appDelegate showWaitingView]; //To remove Waiting View [appDelegate removeWaitingView];Deva
this doesn't seem to work with the iOS5 SDK. The keyboard is on top no matter what.Chalet

© 2022 - 2024 — McMap. All rights reserved.