2

我正在尝试全屏显示活动指示器,因此用户无法按下屏幕上的任何按钮,直到活动指示器作为警报查看过程关闭。我打过电话,[activityView startAnimating]但我可以按后面的按钮。有没有办法防止这种情况?

从现在开始感谢。

4

5 回答 5

1

您可以将MBProgressHUD用于此类加载指示符。这是一个很棒的 MIT 许可类,如果您想进一步定制它,它可以很好地扩展。

于 2012-12-14T10:48:58.587 回答
1

我建议最好的方法是在屏幕上显示带有活动指示器的 alertView。您可以为此使用以下代码:

声明UIAlertView如下属性:

@property (nonatomic, strong) UIAlertView *sendAlert;

self.sendAlert = [[UIAlertView alloc] initWithTitle:@"Loading" message:@"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *act = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
act setFrame:CGRectMake(115, 60, 50, 50)];
[act startAnimating];
[sendAlert addSubview:act];     
act = nil;
[sendAlert show];

当您想删除警报时,您可以使用:

[sendAlert dismissWithClickedButtonIndex:0 animated:YES];   
sendAlert = nil;

另一种选择是,您可以将活动指示器添加到视图本身并将后退按钮的 userInteraction 设置为 false。当你完成任务时设置为 True。但这不会是一个好方法。

于 2012-12-14T10:46:33.107 回答
1

你可以试试这个

 UIAlertView *alert= [[[UIAlertView alloc] initWithTitle:@"Loading\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

indicator.center = CGPointMake(150, 100);
[indicator startAnimating];
[alert addSubview:indicator];

[indicator release];

并将此行添加到您要删除警报的位置

 [alert dismissWithClickedButtonIndex:0 animated:YES];
于 2012-12-14T10:47:55.917 回答
0

嘿,对于您的此要求,请使用以下代码,您可以在每个视图使用中访问该代码..

在文件中添加此波纹管代码和对象,AppDelegate.h如下所示..

UIView *activityView;
UIView *loadingView;
UILabel *lblLoad;

并将下面的代码粘贴到AppDelegate.m文件中

#pragma mark - Loading View
-(void) showLoadingView {
    //NSLog(@"show loading view called");
    if (loadingView == nil) 
    {
        loadingView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 60.0, 320.0, 420.0)];
        loadingView.opaque = NO;
        loadingView.backgroundColor = [UIColor darkGrayColor];
        loadingView.alpha = 0.5;

        UIView *subloadview=[[UIView alloc] initWithFrame:CGRectMake(84.0, 190.0,150.0 ,50.0)];
        subloadview.backgroundColor=[UIColor blackColor];
        subloadview.opaque=NO;
        subloadview.alpha=0.8;

        subloadview.layer.masksToBounds = YES;
        subloadview.layer.cornerRadius = 6.0;

        lblLoad=[[UILabel alloc]initWithFrame:CGRectMake(50.0, 7.0,80.0, 33.0)];
        lblLoad.text=@"LoadingView";
        lblLoad.backgroundColor=[UIColor clearColor];
        lblLoad.textColor=[UIColor whiteColor];
        [subloadview addSubview:lblLoad];

        UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(10.0, 11.0, 25.0, 25.0)];
        [spinningWheel startAnimating];
        spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
        [subloadview addSubview:spinningWheel];
        [loadingView addSubview:subloadview];
        [spinningWheel release];
    }       
    [self.window addSubview:loadingView];

    //[[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
}


-(void) hideLoadingView {
    if (loadingView) {
        [loadingView removeFromSuperview];
        [loadingView release];
        loadingView = nil;
    }

}

并在需要时在任何类中调用此方法,就像下面一样。

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate showLoadingView];
于 2012-12-14T10:47:45.003 回答
0

当活动指示器启动时,在当前视图上方添加一个 UIView :

UIView *overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
[self.navigationController.view addSubview:overlayView];
于 2012-12-14T10:47:53.453 回答