Creating a “loading…” view using iPhone SDK

后端 未结 7 1591
情歌与酒
情歌与酒 2021-02-01 08:57

How to create that black/gray modal popup kind of view that many apps use, when some long pending operation is in progress?

Like when using location based services, load

7条回答
  •  无人共我
    2021-02-01 09:08

    I use LoadingHUDView for this purpose, and it works always.

    get LoadingHUDView.m and LoadingHUDView.h and do the following in your base class (or whatever)

    #pragma mark ActivityIndicator Methods
    
    -(void) showModalActivityIndicator:(NSString *)message 
    {
            loadingView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]retain];//  origional
            //loadingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; //testing
            loadingView.backgroundColor = [UIColor grayColor]; //[UIColor colorWithRed:1 green:1 blue:1 alpha:0.3];
            LoadingHUDView *loadHud = [[LoadingHUDView alloc] initWithTitle:message];
            loadHud.center = CGPointMake(160, 290);
            [loadingView addSubview:loadHud];
            [loadHud startAnimating];
            [loadHud release];
            [loadingView setAlpha:0.0];
              [self.tableView addSubview:loadingView];
            [UIView beginAnimations:@"fadeOutSync" context:NULL];
            [UIView setAnimationDelegate:self];
            [UIView setAnimationDuration:0.5];
            [loadingView setAlpha:0.5];
            [UIView commitAnimations];
    }
    
    -(void) hideModalActivityIndicator {
        if (loadingView) {
        [UIView beginAnimations:@"fadeOutSync" context:NULL];
        [UIView setAnimationDidStopSelector:@selector (removeTranparentView) ];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:0.5];
        [loadingView setAlpha:0];
        [UIView commitAnimations];
            }
    }
    
    -(void)removeTranparentView
    {
        [loadingView removeFromSuperview];
        [loadingView release];
        loadingView = nil;
    }
    

    HOPE THIS HELPS. thank you

提交回复
热议问题