代码之家  ›  专栏  ›  技术社区  ›  Richard

如何在iPhone上使用活动指示器视图?

  •  65
  • Richard  · 技术社区  · 7 年前

    活动指示器视图在许多应用程序中都很有用。

    这里欢迎所有的方法。

    8 回复  |  直到 14 年前
        1
  •  121
  •   Jane Sales    17 年前

    创建:

    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];
    

    最终完成后,将微调器从视图中移除并释放。

        2
  •  10
  •   Lounges    17 年前

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

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

    您需要的文件是:

    • WPActivityIndicator.xib
    • RoundedRectBlack.png
    • WPActivityIndicator.m

    然后,要显示它,请使用以下内容:

    [[WPActivityIndicator sharedActivityIndicator] show];
    

    并隐藏:

    [[WPActivityIndicator sharedActivityIndicator] hide];
    
        3
  •  9
  •   Dani Llewellyn    16 年前

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

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

    如果您不想被迫打开源代码,那么您不能使用wordpress iphone应用程序中的任何内容,包括引用的“活动进度”窗口,而不强制将GPL应用于您自己的。

        4
  •  7
  •   nduplessis    17 年前

    关于这一点的文档非常清楚。它是UIView子类,所以可以像其他视图一样使用它。启动/停止使用的动画的步骤

    [activityIndicator startAnimating];
    [activityIndicator stopAnimating];
    
        5
  •  2
  •   natasha    12 年前

    使用故事板-

    创造-

    • 转到main.storyboard(可以在Xcode左侧的项目导航器中找到),然后从对象库拖放“活动指示器视图”。

    Activity Indicator View from Object Library

    • 转到头文件并为UIActivityIndicatorView创建IBOutlet-

       @interface ViewController : UIViewController
      
           @property (nonatomic,strong) IBOutlet UIActivityIndicatorView *activityIndicatorView;
      
       @end
      
    • 建立从插座到UIActivityIndicator视图的连接。

    开始:

    需要在实现文件(.m)中使用以下代码启动活动指示器时,请使用以下代码-

     [self.activityIndicatorView startAnimating];
    

    停止:

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

     [self.activityIndicatorView stopAnimating];
    
        6
  •  1
  •   bin    15 年前

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

    activityIndicator.hidden = YES
    
        7
  •  0
  •   Bibin Joseph    11 年前

    @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];}
    
        8
  •  0
  •   P.J.Radadiya    10 年前
    - (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"];
        }
    }