如何在一些后台任务正在进行时显示一些处理?
问题描述:
我正在制作一个iPhone应用程序,其中我需要用户输入他们的电子邮件ID和密码,然后他们可以在我的网站上访问他们的帐户。如何在一些后台任务正在进行时显示一些处理?
一旦他们输入认证详细信息,他们必须等待几秒钟才能出现下一页。
我需要向用户显示“正在处理”或“请稍候”类型的符号。
我应该如何实现它?
请帮助我。
答
你在搜索的是一个活动指标。
这里是活动指标的教程。
http://www.edumobile.org/iphone/iphone-programming-tutorials/use-activityindicator-in-iphone/
希望它可以帮助你
答
由于ParthBhatt指出这是你想要一个活动的指标。
我非常喜欢David Sinclair的DSActivityView类:非常容易实现,易于显示和更改消息,如果需要,可以通过覆盖它来禁用UI,包括标签栏和导航栏。
答
我通常创建一个按需被实例化一个UIView。下面是一些代码为你在自己的应用程序尝试:
- (id)initWithLabel:(NSString*)labelName {
self = [super init];
if (self) {
UIImageView *loadingBackgroundView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 150, 120, 40)];
[loadingBackgroundView setBackgroundColor:[UIColor blackColor]];
[loadingBackgroundView setAlpha:0.9];
[loadingBackgroundView.layer setCornerRadius:8.0];
[loadingBackgroundView.layer setBorderColor:[[UIColor clearColor] CGColor]];
[self addSubview:loadingBackgroundView];
[loadingBackgroundView release];
UILabel *loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake (125, 160, 100, 20)];
[loadingLabel setBackgroundColor:[UIColor clearColor]];
[loadingLabel setTextAlignment:UITextAlignmentCenter];
[loadingLabel setTextColor:[UIColor whiteColor]];
[loadingLabel setText:labelName];
[self addSubview:loadingLabel];
[loadingLabel release];
UIActivityIndicatorView *loadingActivityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(110,160,20,20)];
[loadingActivityIndicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
[loadingActivityIndicatorView startAnimating];
[self addSubview:loadingActivityIndicatorView];
[loadingActivityIndicatorView release];
}
return self;
}
这会给你类似如下的内容:
答
这事已被很多人来处理,因此,如果您想要利用别人的工作并避免重新发明轮子,你可以使用类似Tapku Library的东西。它是开源的,在GitHub上。
具体而言,请查看TKProgressAlertView
和TKLoadingView
类。
谢谢马修。 :) – 2010-11-28 09:44:50