关键类:
YYTextAsyncLayer // 异步or同步layer
_YYTextSentinel // 计数用
YYLabel // 继承UIView的富文本控件
两个队列:
YYTextAsyncLayerGetDisplayQueue()
YYTextAsyncLayerGetReleaseQueue()
现介绍两个队列
/// 渲染UI使用的队列
static dispatch_queue_t YYTextAsyncLayerGetDisplayQueue() {
#define MAX_QUEUE_COUNT 16
static int queueCount;
static dispatch_queue_t queues[MAX_QUEUE_COUNT]; // 直接分配16个,后面最大16,即使使用不全,也不会浪费很大内存,
static dispatch_once_t onceToken;
static int32_t counter = 0; // 调用次数
dispatch_once(&onceToken, ^{
/// 当前活跃处理器个数
queueCount = (int)[NSProcessInfo processInfo].activeProcessorCount;
/// 队列个数,不能大于默认值16,最小是1
queueCount = queueCount < 1 ? 1 : queueCount > MAX_QUEUE_COUNT ? MAX_QUEUE_COUNT : queueCount;
/// 初始化queueCount 个线程
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
// iOS 8.0前后有差别
for (NSUInteger i = 0; i < queueCount; i++) {
QOS_MIN_RELATIVE_PRIORITY
dispatch_queue_attr_t attr = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INITIATED, 0); // 队列的描述信息:串行、优先级为USER_INITIATED
queues[i] = dispatch_queue_create("com.ibireme.text.render", attr);// 创建串行队列
}
} else {
for (NSUInteger i = 0; i < queueCount; i++) {
queues[i] = dispatch_queue_create("com.ibireme.text.render", DISPATCH_QUEUE_SERIAL); // 创建串行队列
dispatch_set_target_queue(queues[i], dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));// 设置队列执行target,则队列的任务会丢进target的队列里面执行。
}
}
});
uint32_t cur =<