我想在iOS中使用的活动指标,并不能够。我遵循Stackoverflow上的线程并使用它。这是我写的:UIActivity指标没有显示在iOS应用程序启动
-(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
@Larme。这是我在我的问题中提到的线程http://stackoverflow.com/questions/1850186/iphone-uiactivityindicatorview-not-starting-or-stopping – RookieAppler
嗯,我会做主线程中的动画,并加载或任何如果它不触及用户界面,则希望在另一个线程中同时执行此操作。你可以“重新同步”,有时在最后一步和一步之间做一个小动画。 – Larme