【问题标题】:setTintColor: doesn't redraw UIImageView immediatelysetTintColor:不立即重绘 UIImageView
【发布时间】:2017-03-26 22:40:33
【问题描述】:

我在UICollectionViewCell 中有一个UIImageView,而UIImageView 上的图像使用UIImageRenderingModeAlwaysTemplate 渲染模式。

当我单击单元格时,我将更改UImageViewtintColor,但我发现UIImageView 不会立即重绘。但是,当我单击第二个单元格时,第一个 确实使用其tintColor 进行渲染,而第二个 则没有。

RevealLLDB 中,我发现 tintColor 的设置正确

如果我在LLDB手动设置tintColor,它可以正确显示

. .

【问题讨论】:

  • 您是否有机会在辅助线程中进行tintColor 设置?这听起来像是一个问题,您可能在不是主线程的线程中更新 UI ...

标签: ios objective-c


【解决方案1】:

您需要将屏幕操作代码分派到主队列:

Obj-C:

 dispatch_async(dispatch_get_main_queue(), ^{
    // The tint here
  });

斯威夫特 3:

 DispatchQueue.main.async {
   // The tint here
 }

【讨论】:

    猜你喜欢
    • 2014-09-20
    • 2011-12-05
    • 2015-12-12
    • 1970-01-01
    • 2012-11-07
    • 2014-09-25
    • 1970-01-01
    • 2014-02-13
    • 2017-06-16
    相关资源
    最近更新 更多