Luai Kalkatawi
Luai Kalkatawi

Reputation: 1492

Viewing Activity Indicator in fullscreen

I am trying to display an activity indicator in full screen so the user cannot press any button in the screen till the activity indicator is turned off as the alert view process. I have called the [activityView startAnimating] but I can push the buttons in the back. Is there way to prevent that?

Thanks from now.

Upvotes: 2

Views: 5130

Answers (5)

Midhun MP
Midhun MP

Reputation: 107141

I'll suggest a best way will be displaying an alertView with activity indicator on the screen. You can use the following code for this:

declare property for UIAlertView like:

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

When you want to remove alert you can use:

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

Another alternative, you can add the activity indicator to your view itself and set the userInteraction of backbutton to false. When you finish the task set to True. But It won't be a nice way.

Upvotes: 1

Alexander
Alexander

Reputation: 8147

You can use MBProgressHUD for such loading indictators. It's a great MIT-licensed class that extends well if you want to customize it further.

Upvotes: 1

Sudha Tiwari
Sudha Tiwari

Reputation: 2451

you can try this

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

and add this line where you want remove your alert

 [alert dismissWithClickedButtonIndex:0 animated:YES];

Upvotes: 1

Anusha Kottiyal
Anusha Kottiyal

Reputation: 3905

Add a UIView above your current view when activity indicator starts :

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

Upvotes: 0

Paras Joshi
Paras Joshi

Reputation: 20541

hey for your this requirement use the bellow code which you can access in your every view use..

add this bellow code and object in AppDelegate.h file like bellow..

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

and paste this bellow code in AppDelegate.m file

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

}

and call this method when you want in any class , just like bellow..

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate showLoadingView];

Upvotes: 0

Related Questions