【问题标题】:Show a view over the keyboard在键盘上显示视图
【发布时间】:2011-09-26 12:10:22
【问题描述】:

由于自定义“加载”子视图,我正在 iPhone 上寻找一种方法,让子视图覆盖键盘而不关闭键盘。现在当子视图加载时,键盘仍然是最上面的。有什么想法吗?

【问题讨论】:

  • 每当您将子视图添加到当前视图时,只需在添加子视图之前编写此代码 [TextView resignFirstResponder];当您从 UITextView 打开键盘时。

标签: iphone objective-c iphone-softkeyboard


【解决方案1】:
UIWindow *window = [UIApplication sharedApplication].windows.lastObject;
[window addSubview:self.view];                                                                                                                                                                                                                                        
[window bringSubviewToFront:self.view];

【讨论】:

  • 我们怎样才能把UIPopoverController放在前面?
【解决方案2】:
@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];

【讨论】:

  • 太棒了!当键盘出现时 - 计数将是 2
  • 只需将视图添加到[UIApplication sharedApplication].windows.lastObject 也可以,谢谢。
【解决方案3】:

将加载视图添加为窗口上的子视图。它也会覆盖键盘。这是相同的stackoverflow帖子

IPhone - Show Wait Indicator

更新

我的代码

#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];

}

【讨论】:

  • 感谢您的链接。实际上 MBProgressHUD 是我想要实现的。但是,我希望键盘始终保持可见,并且 MBProgressHUD 位于键盘后面。
  • @Jake Sankey 您可以将 mbprogresshud 添加到窗口而不是当前视图。我发布了一个简单的代码来显示活动指示器。你可以使用它。
  • 我的实现文件中没有“窗口”。它在应用程序委托中。我试过 [super.view.window addSubview:HUD];没有运气......
  • 您在 applicationDelegate 中有窗口。您需要从应用委托调用此函数。
  • 这似乎不适用于 iOS5 SDK。无论如何,键盘都在上面。
猜你喜欢
  • 2016-01-08
  • 2023-03-09
  • 1970-01-01
  • 2022-01-04
  • 2014-03-08
  • 2014-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多