全屏查看活动指示器

时间:2012-12-14 10:44:46

标签: iphone ios xcode uiactivityindicatorview

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

谢谢你们。

5 个答案:

答案 0 :(得分:2)

您可以将MBProgressHUD用于此类加载指示符。如果你想进一步定制它,这是一个很好的麻省理工学院许可课程。

答案 1 :(得分: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;

另一种方法是,您可以将活动指示符添加到视图本身,并将backbutton的userInteraction设置为false。完成任务设置为True后。但它不是一个好方法。

答案 2 :(得分: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];

答案 3 :(得分:0)

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

将这个波纹管代码和对象添加到AppDelegate.h文件中,如bellow ..

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

答案 4 :(得分: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];