我有一个奇怪的问题,我需要动画if (chbInsurance.Checked == true)
txtCost.Text = ((Convert.ToDouble(txtHours.Text.ToString())) * costPerHour + costOfInsurance).ToString();
当我从Activity Indicator
选择Cell
时。
我的问题是在使用断点调试代码时,CollectionView
是动画的,但在运行应用Activity Indicator
时没有出现断点。请帮助。
Activity Indicator
答案 0 :(得分:1)
看起来dispatch_get_global_queue
根本没用过!
一切都在主线程上运行,这对它来说是一个巨大的负担。删除'dispatch_async'块仅在主线程中使用,ui元素会更新。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
//Keep rest of code lines here...
});
});
如果仍然看不到活动指标,则尝试将繁重的任务移至后台线程并显示活动指示符,如
loading = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
loading.frame = CGRectMake(round((self.view.frame.size.width - 25) / 2), round((self.view.frame.size.height - 25) / 2), 25, 25);
[self.view addSubview:loading];
[loading startAnimating];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
//Heavy tasks at background thread
NSString *videoStringUrl=[NSString stringWithFormat:@"%@",[[arrayPhotos objectAtIndex:indexPath.row]valueForKey:@"source"]];
VideoURL=[NSURL URLWithString:videoStringUrl];
dispatch_async(dispatch_get_main_queue(), ^{
//After completion stop animating activity indicator
[loading stopAnimating];
AVURLAsset *sourceAsset = [AVURLAsset URLAssetWithURL:VideoURL options:nil];
CMTime duration = sourceAsset.duration;
float seconds = CMTimeGetSeconds(duration);
if (seconds<4) {
[self performSegueWithIdentifier:@"Edit" sender:self];
}
else
{
[self performSegueWithIdentifier:@"Trimmer" sender:self];
}
});});
答案 1 :(得分:1)
你正在改变队列,所以经常有一些延迟来解决它。
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
//Keep rest of code lines here...
});
});