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

发布于 2024-07-14 02:43:05 字数 88 浏览 7 评论 0原文

活动指示器视图在许多应用程序中都很有用。 关于如何在 iPhone 上添加、激活和关闭活动指示器视图有什么想法吗?

这里欢迎所有的方法。

An activity indicator view is useful in many applications.
Any ideas about how to add, activiate and dismiss an activity indicator view on iPhone?

All the methods for this are welcomed here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

左岸枫 2024-07-21 02:43:06

创建:

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

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

Create:

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

Start:

[spinner startAnimating]; 

Stop:

 [spinner stopAnimating];

When you're finally done, remove the spinner from the view and release.

泛滥成性 2024-07-21 02:43:06

看一下开源 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];

Take a look at the open source WordPress application. They have a very re-usable window they have created for displaying an "activity in progress" type display over top of whatever view your application is currently displaying.

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

The files you want are:

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

Then to show it use something like:

[[WPActivityIndicator sharedActivityIndicator] show];

And hide with:

[[WPActivityIndicator sharedActivityIndicator] hide];
手心的海 2024-07-21 02:43:06

关于:

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

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

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

in regards to:

Take a look at the open source WordPress application. They have a very re-usable window they have created for displaying an "activity in progress" type display over top of whatever view your application is currently displaying.

note that if you do utilise this code you MUST provide ALL the sourcecode to your own application to any user that requests it. You need to be aware that they may decide to repackage your code and sell it on the store themselves. This is all provided for under the terms of the GNU General Public License (GPL).

If you don't want to be forced into opening your sourcecode then you cannot use anything from the wordpress iphone application including the, referenced activity progress window, without forcing the GPL to apply to your own.

初见终念 2024-07-21 02:43:06

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

[activityIndicator startAnimating];
[activityIndicator stopAnimating];

The documentation on this is pretty clear. It's a UIView subclass so you use it like any other view. To start/stop the animation you use

[activityIndicator startAnimating];
[activityIndicator stopAnimating];
负佳期 2024-07-21 02:43:06

使用 Storyboard-

创建-

  • 转到 main.storyboard(可以在 Xcode 左侧的 Project Navigator 中找到)并拖动并从对象库中删除“活动指示器视图”。

对象库中的活动指示器视图

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

     @interface ViewController : UIViewController 
    
           @property (非原子,强) IBOutlet UIActivityIndi​​catorView *activityIndi​​catorView; 
    
       @结尾 
      
  • 建立从 Outlets 到 UIActivityIndi​​catorView 的连接。

开始:

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

 [self.activityIndicatorView startAnimating];

停止:

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

 [self.activityIndicatorView stopAnimating];

Using Storyboard-

Create-

  • Go to main.storyboard (This can be found in theProject Navigator on the left hand side of your Xcode) and drag and drop the "Activity Indicator View" from the Object Library.

Activity Indicator View from Object Library

  • Go to the header file and create an IBOutlet for the UIActivityIndicatorView-

     @interface ViewController : UIViewController
    
         @property (nonatomic,strong) IBOutlet UIActivityIndicatorView *activityIndicatorView;
    
     @end
    
  • Establish the connection from the Outlets to the UIActivityIndicatorView.

Start:

Use the following code when you need to start the activity indicator using following code in your implementation file(.m)-

 [self.activityIndicatorView startAnimating];

Stop:

Use the following code when you need to stop the activity indicator using following code in your implementation file(.m)-

 [self.activityIndicatorView stopAnimating];
旧夏天 2024-07-21 02:43:06

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

activityIndicator.hidden = YES

i think you should use hidden better.

activityIndicator.hidden = YES
jJeQQOZ5 2024-07-21 02:43:06

活动指示器 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];}

Activity indicator 2 sec show and go to next page

@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];}
謸气贵蔟 2024-07-21 02:43:06
- (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"];
    }
}
- (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"];
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文