在TableView的Cell中用到了YYLabel的富文本,然后在刷新的時(shí)候頁(yè)面總是會(huì)閃一下暇屋。
IMG_E9F10EC08145-1.jpeg
一直以為是tableView刷新的問(wèn)題導(dǎo)致的,最后發(fā)現(xiàn)是YYLabel
中對(duì)富文本賦值導(dǎo)致的存璃。
這是之前出問(wèn)題的代碼:
[[RACObserve(self, model) ignore:nil] subscribeNext:^(id _Nullable x) {
((YYLabel *)self.detailLab).attributedText = [LHTemplateCellViewModel buildDetailTextWithModel:x];
}];
[[self rac_prepareForReuseSignal] subscribeNext:^(RACUnit * _Nullable x) {
@strongify(self);
self.iconView.image = [UIImage imageNamed:@"template_placehold"];
((YYLabel *)self.detailLab).attributedText = nil;
((YYLabel *)self.detailLab).text = nil;
}];
在YYLabel中是基于CoreText 進(jìn)行繪制的一個(gè)框架狂巢,所有的元素是繪制在Layer上的。
在清除富文本內(nèi)容恋脚,這個(gè)是個(gè)異步操作,如果cell被復(fù)用焰手,在重新賦值的時(shí)候糟描,這里的異步操作會(huì)導(dǎo)致在label先顯示了復(fù)用前的text內(nèi)容,然后更新為新的內(nèi)容书妻,所以這里總是會(huì)閃一下船响。
這里又復(fù)習(xí)了一遍YYLabel的源碼,后面再詳細(xì)解釋一遍