【问题标题】:IOS warning on background thread后台线程上的 IOS 警告
【发布时间】:2017-03-06 08:34:09
【问题描述】:

我正在后台线程上下载图像并在主线程上将此图像设置为UIImageView。但它给了我一些警告,比如

Using low GPU priority for background rendering

另外请查看以下代码以供参考

 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) {
     int randomImgNum = [[contentDict valueForKey:@"imageIndex"]intValue];
     UIImage *image = [UIImage imageNamed:[Utils getImageFromIndex:randomImgNum]];
     UIImage *newBlurredImage = [image blurredImageWithRadius:5.0];
     dispatch_sync(dispatch_get_main_queue(), ^(void) {
         customVieww.imgCardView.image = image;
         [self setBlurrImage:newBlurredImage];
     });
 });

请让我知道可能是什么问题以及我们如何解决它。

如果我遗漏了什么,请告诉我任何解释。

提前谢谢你。

【问题讨论】:

  • 为什么 DISPATCH_QUEUE_PRIORITY_BACKGROUND 不是 DISPATCH_QUEUE_PRIORITY_DEFAULT
  • 谢谢你,麦克我也试过这个解决方案,但仍然收到同样的警告
  • 我认为问题是由blurredImageWithRadius 引起的。您可以发布该特定方法的代码吗?

标签: ios objective-c iphone background


【解决方案1】:

如果你想在主视图上工作,你必须使用主队列 因为如果您使用后台队列来更改 UIView 可能会导致问题

更新代码:

dispatch_async(dispatch_get_main_queue(), ^{
     int randomImgNum = [[contentDict valueForKey:@"imageIndex"]intValue];
     UIImage *image = [UIImage imageNamed:[Utils getImageFromIndex:randomImgNum]];
     UIImage *newBlurredImage = [image blurredImageWithRadius:5.0];
     dispatch_sync(dispatch_get_main_queue(), ^(void) {
         customVieww.imgCardView.image = image;
         [self setBlurrImage:newBlurredImage];
     });
 });

【讨论】:

  • 你能解释一下后台队列中运行的进程在给定问题中影响 UI 吗?
  • 谢谢兄弟,但我们没有更新后台线程上的任何 UI,如果我们不使用任何后台线程,main_queue 的用途是什么
【解决方案2】:

【讨论】:

  • 谢谢@KKRocks,但这里的解决方案是我哪里出错了。
  • 为每个矩形创建一个 CALayer 并将它们添加为 UIImage 的子层。 CALayer 层次结构由 GPU 渲染。
猜你喜欢
  • 2015-09-23
  • 2012-06-14
  • 2011-11-17
  • 2013-03-08
  • 1970-01-01
  • 2011-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多