iPhone活动指示器

时间:2011-05-02 09:06:41

标签: ios cocoa-touch loading uiactivityindicatorview

如何在登录页面中加载UIActivityIndicatorView?就像facebook iPhone App。

4 个答案:

答案 0 :(得分:7)

你的问题不明确。但这是添加活动指标的方法。

UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(225, 115, 30, 30)];
[activity setBackgroundColor:[UIColor clearColor]];
[activity setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:activity];
[activity release];

开始动画活动

[activity startAnimating];

停止动画活动

[activity stopAnimating];

答案 1 :(得分:2)

activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    activityIndicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
    activityIndicator.center = self.view.center;
    [self.view addSubview: activityIndicator];

想要动画

时使用[activityIndicator startAnimating];

答案 2 :(得分:2)

像这样初始化..

UIActivityIndicatorView *activityView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
activityView.center = CGPointMake(240,160);
activityView.hidden = true;
[self.view addSubview: activityView];

当你想要动画

   activityView.hidden = FALSE;
   [activityView startAnimating] ;

当你想要停止时

   [activityView stopAnimating];
   activityView.hidden = TRUE;

编辑:看到评论后

Facebook活动指标没有什么特别之处。他们只是清除那里的视图,同时显示活动指标何时开始动画..

您只需创建一个视图,例如ActivityView,它覆盖屏幕(或任何您想要变白的部分),将白色背景添加到视图中,并将活动指示符添加到视图中。首先隐藏此视图,当你想要显示活动指示器时取消隐藏视图并启动活动指示器动画。在活动指示器中写入两个成员函数来启动和停止动画,这样你就可以从任何地方控制动画..

答案 3 :(得分:1)

CGRect frame = CGRectMake(self.view.frame.size.width/2-15, self.view.frame.size.height/2-15, 37, 37);
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithFrame:frame];
    [indicator startAnimating];
    indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    [indicator sizeToFit];
    indicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                                    UIViewAutoresizingFlexibleRightMargin |
                                    UIViewAutoresizingFlexibleTopMargin |
                                    UIViewAutoresizingFlexibleBottomMargin);

    indicator.tag = 1;
    [self.view addSubview:indicator];
    [indicator release];