活动指示器视图在许多应用程序中非常有用。
有什么关于如何在iPhone上添加、激活和取消活动指示器视图的方法吗?
欢迎分享所有相关的方法。
活动指示器视图在许多应用程序中非常有用。
有什么关于如何在iPhone上添加、激活和取消活动指示器视图的方法吗?
欢迎分享所有相关的方法。
创建:
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];
当你最终完成时,从视图中移除旋转器并释放。
可以看一下开源的WordPress应用程序。他们创建了一个非常可重用的窗口,用于在你的应用程序当前显示的任何视图之上显示“正在进行中”的活动类型的显示。
http://iphone.trac.wordpress.org/browser/trunk
你需要的文件是:
然后像这样展示它:
[[WPActivityIndicator sharedActivityIndicator] show];
并通过以下方式隐藏:
[[WPActivityIndicator sharedActivityIndicator] hide];
关于:
看看开源的WordPress应用程序。他们创建了一个非常可重复使用的窗口,用于在当前应用程序显示的任何视图上显示“正在进行的活动”类型的显示。
请注意,如果您使用此代码,则必须向请求它的任何用户提供您自己应用程序的所有源代码。您需要知道,他们可能会决定重新打包您的代码并将其自己销售。这全部都是根据GNU通用公共许可证(GPL)的条款提供的。
如果您不想被强制开放源代码,则不能使用WordPress iPhone应用程序中的任何内容,包括引用的活动进度窗口,而不会强制GPL适用于您自己的应用程序。
关于此事的文档已经很明确了。它是UIView的子类,因此您可以像使用任何其他视图一样使用它。要开始/停止动画,您可以使用
[activityIndicator startAnimating];
[activityIndicator stopAnimating];
使用Storyboard-
创建-
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.
开始:
在你的实现文件(.m)中,当你需要使用以下代码启动活动指示器时,请使用以下代码-
[self.activityIndicatorView startAnimating];
注意:
如果您需要在实现文件(.m)中停止活动指示器,请使用以下代码:
[self.activityIndicatorView stopAnimating];
我认为你应该更好地使用隐藏。
activityIndicator.hidden = YES
- (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"];
}
}
活动指示器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];}