Show a view over the keyboard

Jake Sankey picture Jake Sankey · Jul 1, 2011 · Viewed 14k times · Source

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?

Answer

Kota Mizuguchi picture Kota Mizuguchi · Dec 8, 2011
@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];