Show a view over the keyboard

后端 未结 3 1793
失恋的感觉
失恋的感觉 2020-12-09 13:39

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 l

相关标签:
3条回答
  • 2020-12-09 14:24
    UIWindow *window = [UIApplication sharedApplication].windows.lastObject;
    [window addSubview:self.view];                                                                                                                                                                                                                                        
    [window bringSubviewToFront:self.view];
    
    0 讨论(0)
  • 2020-12-09 14:25

    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];
    
    }
    
    0 讨论(0)
  • 2020-12-09 14:28
    @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];
    
    0 讨论(0)
提交回复
热议问题