【发布时间】:2013-01-17 21:12:29
【问题描述】:
我正在尝试在 iOS 中使用活动指示器但无法使用。我在 Stackoverflow 上关注了一个线程并像这样使用它。这是我写的:
-(void)viewDidLoad
{
[NSThread detachNewThreadSelector:@selector(threadStartAnimating:) toTarget:self withObject:self];
UITapGestureRecognizer *tGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doThisForTap:)];
tGR.numberOfTapsRequired = 1;
[myRollTypeLabel addGestureRecognizer:tGR];
myRollTypeLabel.userInteractionEnabled = YES;
[self.scrollView addSubview:myRollTypeLabel];
}
- (void) threadStartAnimating:(id)data
{
self.activityIndicatorNew =[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.activityIndicatorNew.color = [UIColor redColor];
[self.activityIndicatorNew startAnimating];
}
- (void)doThisForTap :(UIGestureRecognizer *)gest
{
//lots of computation.
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.activityIndicatorNew stopAnimating];
self.activityIndicatorNew.hidden = YES;
}
但活动指示器根本不显示?在“doThisForTap”方法中,我进行计算并移动到另一个 UIViewController。但我看不到活动指示器。我究竟做错了什么?如果您需要更多信息,请询问。谢谢..
【问题讨论】:
-
我认为 NSThread 不能在 UIKit 中使用(非线程安全)。
-
@Larme。这是我在我的问题stackoverflow.com/questions/1850186/… 中提到的线程
-
好吧,我会在主线程中做动画,如果它不接触 UI,那么加载或你想要同时在另一个线程中做的任何事情。您有时可以“重新同步”以在最终结束和步骤之间制作一个小动画。
-
@Larme 正确。他不应该做他正在做的事情。
标签: ios animation nsthread uiactivityindicatorview