1

在静态库(lib.a)中,我NavigationController在 Storyboard 中有一个在点击按钮后启动的:

[mainWindow.rootViewController presentViewController:newController animated:NO completion:Nil];

在其中newController我有一个UITextField我设置becomeFirstResponderviewDidLoad按钮和另一个按钮,当我点击它时我想显示一个UIAlertView,在按下“确定”后应该UIActivityIndicatorView在所有东西(包括键盘)的顶部显示一个。

用于显示的代码UIActivityIndicatorView如下

UIWindow *mainWindow = [[UIApplication sharedApplication] keyWindow];
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
spinner.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                            UIViewAutoresizingFlexibleRightMargin |
                            UIViewAutoresizingFlexibleTopMargin |
                            UIViewAutoresizingFlexibleBottomMargin);
spinner.center = CGPointMake(CGRectGetWidth(mainWindow.bounds)/2, CGRectGetHeight(mainWindow.bounds)/2);
spinner.frame = mainWindow.bounds;
spinner.backgroundColor = [UIColor darkGrayColor];
spinner.alpha = 0.7f;
[mainWindow addSubview:spinner];

每当用户点击按钮时,我都会执行以下操作:

UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Confirmation"
                                                      message:@"Are you sure?"
                                                     delegate:self
                                            cancelButtonTitle:@"No"
                                            otherButtonTitles:@"Yes", nil];
[message show];

当被点击时,我有一个简单的方法:

//Initializing spinner
[spinner startAnimating];

 //Execute NSURL Connection....

问题是UIActivityIndicatorView键盘顶部没有显示。

有任何想法吗?

4

2 回答 2

0

尝试添加后

[mainWindow addSubview:spinner];

就像是

[mainWindow bringSubviewToFront:spinner];

尝试将此视图用作 UIActivityIndi​​catorView 的超级视图

- (UIView *)keyboardView {
    NSArray *windows = [[UIApplicatio sharedApplication] windows];
    for (UIWindow *window in [windows reverseObjectEnumerator]) {
        for (UIView *view in [window subviews]) {
            if (!strcmp(object_getClassName(view), "UIKeyboard"))  {
                return view;
            }
        }
    }

    return nil;
}
于 2013-02-20T20:44:10.663 回答
0

在显示指标之前将 设置UIActivityIndicatorView为窗口的最前面的子视图

添加代码:[mainWindow bringSubviewToFront:spinner];之前[spinner startAnimating];

于 2013-02-21T02:09:14.827 回答