开发者

iOS waiting screen

开发者 https://www.devze.com 2023-03-12 10:17 出处:网络
When my app is launched I\'d like to display a kind of \"waiting view\" so I can make the first http calls before accessing to the app.

When my app is launched I'd like to display a kind of "waiting view" so I can make the first http calls before accessing to the app.

I saw a nice one, all grey and a little transparent with only an activity indicator inside.

I do not really know how to build this kind of view in a good manner, is it开发者_开发问答 a simple UIView ?


Fist short answer is: yes, the simplest way is to use a UIActivityIndicatorView.

If you don't like all this "big" static libraries just use this:

#import <QuartzCore/QuartzCore.h>

.....

- (UIActivityIndicatorView *)showActivityIndicatorOnView:(UIView*)aView
{
    CGSize viewSize = aView.bounds.size;

    // create new dialog box view and components
    UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc]
    initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    // other size? change it
    activityIndicatorView.bounds = CGRectMake(0, 0, 65, 65);
    activityIndicatorView.hidesWhenStopped = YES;
    activityIndicatorView.alpha = 0.7f;
    activityIndicatorView.backgroundColor = [UIColor blackColor];
    activityIndicatorView.layer.cornerRadius = 10.0f;

    // display it in the center of your view
    activityIndicatorView.center = CGPointMake(viewSize.width / 2.0, viewSize.height / 2.0);

    [aView addSubview:activityIndicatorView];

    [activityIndicatorView startAnimating];

    return activityIndicatorView;
}

This needs access to a QuartzCore class so add it in to you frameworks. After you task is done send it a stopAnimating and it will disappear. If you don't need it anymore remove it from your view to save memory (btw. this is ARC code).

I call it like this

self.activityIndicatorView = [self showActivityIndicatorOnView:self.parentViewController.view];

In this case I have UINavigationViewController as a main view controller in my app. This is importent because the activity indicator should show up in the middle of the screen and not e.g. in the middle of a table view.

The simplest implementation is this:

- (UIActivityIndicatorView *)showSimpleActivityIndicatorOnView:(UIView*)aView
{
    CGSize viewSize = aView.bounds.size;

    // create new dialog box view and components
    UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

    activityIndicatorView.center = CGPointMake(viewSize.width / 2.0, viewSize.height / 2.0);

    [aView addSubview:activityIndicatorView];

    [activityIndicatorView startAnimating];

    return activityIndicatorView;
}


MBProgressHUD might be what you're looking for:
https://github.com/matej/MBProgressHUD

iOS waiting screen


There are many many way to do this, but yes, it can be a simple UIView.

Maybe you should give a look at three20 library which offers built-in loaders TTActivityLabel like these:

iOS waiting screen

0

精彩评论

暂无评论...
验证码 换一张
取 消