2009-02-27 93 views
64

活动指示器视图在许多应用程序中很有用。 关于如何在iPhone上添加,激活和解除活动指示器视图的任何想法?如何在iPhone上使用活动指示器视图?

这里的所有方法都欢迎在这里。

+0

我发现[MBProgressHUD](https://github.com/jdg/MBProgressHUD),它提供了一个不错的模式指示器。这很容易实现。 – foz 2011-01-13 21:08:38

回答

121

创建:

spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
[spinner setCenter:CGPointMake(kScreenWidth/2.0, kScreenHeight/2.0)]; // I do this because I'm in landscape mode 
[self.view addSubview:spinner]; // spinner is not visible until started 

开始:

[spinner startAnimating]; 

停止:

[spinner stopAnimating]; 

当您终于完成时,从视图中删除微调器并释放。

7

关于此的文档非常清晰。这是一个UIView子类,因此您可以像使用其他视图一样使用它。开始/停止使用的动画

[activityIndicator startAnimating]; 
[activityIndicator stopAnimating]; 
10

看看开放源代码的WordPress应用程序。他们有一个非常可重用的窗口,用于显示应用程序当前显示的任何视图顶部的“正在进行的活动”类型显示。

http://iphone.trac.wordpress.org/browser/trunk

你想要的文件有:

  • WPActivityIndi​​cator.xib
  • RoundedRectBlack.png
  • WPActivityIndi​​cator.h
  • WPActivityIndi​​cator.m

然后要显示它使用类似:

[[WPActivityIndicator sharedActivityIndicator] show]; 

并与隐藏:

[[WPActivityIndicator sharedActivityIndicator] hide]; 
+2

谢谢,我正在寻找的也是。请注意,WPActivityIndi​​cator已被重命名(并重构)为WPProgressHUD(请参阅http://iphone.trac.wordpress.org/browser/trunk/Classes/WPProgressHUD.h)。 – 2009-07-19 06:00:27

+0

sharedActivityIndi​​cator在您的链接中找不到类methos方法。 – 2012-09-19 06:41:40

9

的问候:

看看开源WordPress应用。他们有一个非常可重用的窗口,用于显示应用程序当前显示的任何视图顶部的“正在进行的活动”类型显示。

请注意,如果您确实使用此代码,您必须将所有源代码提供给您自己的应用程序给任何请求它的用户。您需要意识到他们可能决定重新包装您的代码并将其在商店中出售。这一切都是在GNU通用公共许可证(GPL)的条款下提供的。

如果你不想被迫打开你的源代码,那么你不能使用wordpress iphone应用程序中的任何东西,包括引用的活动进度窗口,而不会强制GPL应用到你自己的应用程序中。

1

我认为你应该使用隐藏更好。

activityIndicator.hidden = YES 
2

使用Storyboard-

Create-

  • 转到main.storyboard(这可以在theProject导航发现您的Xcode的左侧)并从对象库中拖放“活动指示器视图”。

Activity Indicator View from Object Library

  • 转到头文件,并创建一个IBOutlet为UIActivityIndi​​catorView-

    @interface ViewController : UIViewController 
    
        @property (nonatomic,strong) IBOutlet UIActivityIndicatorView *activityIndicatorView; 
    
    @end 
    
  • 建立从奥特莱斯到UIActivityIndi​​catorView的连接。

开始:

使用下面的代码时,你需要在实现文件中使用下面的代码来启动活动的指标(.M) -

[self.activityIndicatorView startAnimating]; 

停止:

当需要使用followi停止活动指示器时,请使用以下代码在实现文件NG代码(.M) -

[self.activityIndicatorView stopAnimating]; 
0

活动指示灯2秒显示,进入下一页

@property(strong,nonatomic)IBOutlet UIActivityIndicator *activityindctr; 

-(void)viewDidload { [super viewDidload];[activityindctr startanimating]; [self performSelector:@selector(nextpage) withObject:nil afterDelay:2];} 

-(void)nextpage{ [activityindctr stopAnimating]; [self performSegueWithIdentifier:@"nextviewcintroller" sender:self];} 
0
- (IBAction)toggleSpinner:(id)sender 
{ 
    if (self.spinner.isAnimating) 
    { 
     [self.spinner stopAnimating]; 
     ((UIButton *)sender).titleLabel.text = @"Start spinning"; 
     [self.controlState setValue:[NSNumber numberWithBool:NO] forKey:@"SpinnerAnimatingState"]; 
    } 
    else 
    { 
     [self.spinner startAnimating]; 
     ((UIButton *)sender).titleLabel.text = @"Stop spinning"; 
     [self.controlState setValue:[NSNumber numberWithBool:YES] forKey:@"SpinnerAnimatingState"]; 
    } 
} 
相关问题