UIActivityIndicatorView or similar

前端 未结 6 1093
攒了一身酷
攒了一身酷 2021-01-30 18:44


(source: tumblr.com)

Can anyone tell me how to achieve such loading message? is it some variation of UIActivityIndicatorView? thanks peter

6条回答
  •  执念已碎
    2021-01-30 19:49

    My way of doing this works much simpler and smooth for me;

    Design your loading view in Interface Builder inside your "MainWindow.xib" which is available all through the lifetime of the app (of course if you have one, depending on the type and structure of choice) If you dont have one, just design it inside some view where you can programmatically grab a pointer from your main AppDelegate (use your taste of design choice, but using MainWindow.xib is the easiest)

    Then map this view to a variable in your YourApp class which is the infamous app delegate class of yours.

    Let the designed View map to an IBOutlet named "loading" 
    inside your app delegate class "YourApp" 
    by using the Interface Builder's wiring
    

    Then, put the following functions in some class and enjoy them

    This for showing the loading view just before you run some expensive stuff;

    +(void)showLoading {
        YourApp* app = (YourApp*)[[UIApplication sharedApplication] delegate];
        [UIApplication sharedApplication].networkActivityIndicatorVisible = true;
        [app.loading removeFromSuperview];
        [app.window addSubview:app.loading];
        app.loading.alpha = 0.0;
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.50];
        app.loading.alpha = 0.8;
        [UIView commitAnimations];
    }
    

    and this to remove it from the callback or whatever it goes when the expensive action is completed;

    +(void)hideLoading {
        [UIApplication sharedApplication].networkActivityIndicatorVisible = false;
        YourApp* app = (YourApp*)[[UIApplication sharedApplication] delegate];
        [app.loading removeFromSuperview];
    }
    

    P.S: And yes I use NULL, true, false instead of nil, YES, NO for obvious reasons...

    Hope it helps, Enjoy...

提交回复
热议问题