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?
Show a view over the keyboard
Asked Answered
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
add your loading view as subview on window. It will cover keyboard too. Here is a stackoverflow post for the same
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];
}
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
@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];
great! when keyboard is appeared - count will be 2 –
Unilocular
Just add the view to
[UIApplication sharedApplication].windows.lastObject
also work, thanks. –
Cesarean UIWindow *window = [UIApplication sharedApplication].windows.lastObject;
[window addSubview:self.view];
[window bringSubviewToFront:self.view];
how can we get front the
UIPopoverController
to front? –
Generic add your loading view as subview on window. It will cover keyboard too. Here is a stackoverflow post for the same
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];
}
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.