{"id":1171,"url":"https://github.com/ibireme/YYAsyncLayer","last_synced_at":"2025-07-30T20:32:36.948Z","repository":{"id":56929948,"uuid":"45829862","full_name":"ibireme/YYAsyncLayer","owner":"ibireme","description":"iOS utility classes for asynchronous rendering and display.","archived":false,"fork":false,"pushed_at":"2020-03-13T12:45:32.000Z","size":39,"stargazers_count":681,"open_issues_count":13,"forks_count":119,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-11-22T21:09:50.820Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ibireme.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-09T10:02:28.000Z","updated_at":"2024-11-07T05:49:16.000Z","dependencies_parsed_at":"2022-08-21T06:20:32.990Z","dependency_job_id":null,"html_url":"https://github.com/ibireme/YYAsyncLayer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibireme%2FYYAsyncLayer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibireme%2FYYAsyncLayer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibireme%2FYYAsyncLayer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibireme%2FYYAsyncLayer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibireme","download_url":"https://codeload.github.com/ibireme/YYAsyncLayer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228187541,"owners_count":17882322,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:15:40.463Z","updated_at":"2024-12-04T20:31:02.366Z","avatar_url":"https://github.com/ibireme.png","language":"Objective-C","funding_links":[],"categories":["Graphics","UI","iOS"],"sub_categories":["Getting Started","Other free courses","Linter","YYKit"],"readme":"YYAsyncLayer\n==============\n\n[![License MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/ibireme/YYAsyncLayer/master/LICENSE)\u0026nbsp;\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\u0026nbsp;\n[![CocoaPods](http://img.shields.io/cocoapods/v/YYAsyncLayer.svg?style=flat)](http://cocoapods.org/pods/YYAsyncLayer)\u0026nbsp;\n[![CocoaPods](http://img.shields.io/cocoapods/p/YYAsyncLayer.svg?style=flat)](http://cocoadocs.org/docsets/YYAsyncLayer)\u0026nbsp;\n[![Support](https://img.shields.io/badge/support-iOS%206%2B%20-blue.svg?style=flat)](https://www.apple.com/nl/ios/)\u0026nbsp;\n[![Build Status](https://travis-ci.org/ibireme/YYAsyncLayer.svg?branch=master)](https://travis-ci.org/ibireme/YYAsyncLayer)\n\niOS utility classes for asynchronous rendering and display.\u003cbr/\u003e\n(It was used by [YYText](https://github.com/ibireme/YYText))\n\n\nSimple Usage\n==============\n\n```objc\n@interface YYLabel : UIView\n@property NSString *text;\n@property UIFont *font;\n@end\n\n@implementation YYLabel\n\n- (void)setText:(NSString *)text {\n    _text = text.copy;\n    [[YYTransaction transactionWithTarget:self selector:@selector(contentsNeedUpdated)] commit];\n}\n\n- (void)setFont:(UIFont *)font {\n    _font = font;\n    [[YYTransaction transactionWithTarget:self selector:@selector(contentsNeedUpdated)] commit];\n}\n\n- (void)layoutSubviews {\n    [super layoutSubviews];\n    [[YYTransaction transactionWithTarget:self selector:@selector(contentsNeedUpdated)] commit];\n}\n\n- (void)contentsNeedUpdated {\n    // do update\n    [self.layer setNeedsDisplay];\n}\n\n#pragma mark - YYAsyncLayer\n\n+ (Class)layerClass {\n    return YYAsyncLayer.class;\n}\n\n- (YYAsyncLayerDisplayTask *)newAsyncDisplayTask {\n    \n    // capture current state to display task\n    NSString *text = _text;\n    UIFont *font = _font;\n    \n    YYAsyncLayerDisplayTask *task = [YYAsyncLayerDisplayTask new];\n    task.willDisplay = ^(CALayer *layer) {\n        //...\n    };\n    \n    task.display = ^(CGContextRef context, CGSize size, BOOL(^isCancelled)(void)) {\n        if (isCancelled()) return;\n        NSArray *lines = CreateCTLines(text, font, size.width);\n        if (isCancelled()) return;\n        \n        for (int i = 0; i \u003c lines.count; i++) {\n            CTLineRef line = line[i];\n            CGContextSetTextPosition(context, 0, i * font.pointSize * 1.5);\n            CTLineDraw(line, context);\n            if (isCancelled()) return;\n        }\n    };\n    \n    task.didDisplay = ^(CALayer *layer, BOOL finished) {\n        if (finished) {\n            // finished\n        } else {\n            // cancelled\n        }\n    };\n    \n    return task;\n}\n@end\n```\n\nInstallation\n==============\n\n### CocoaPods\n\n1. Add `pod 'YYAsyncLayer'` to your Podfile.\n2. Run `pod install` or `pod update`.\n3. Import \\\u003cYYAsyncLayer/YYAsyncLayer.h\\\u003e.\n\n\n### Carthage\n\n1. Add `github \"ibireme/YYAsyncLayer\"` to your Cartfile.\n2. Run `carthage update --platform ios` and add the framework to your project.\n3. Import \\\u003cYYAsyncLayer/YYAsyncLayer.h\\\u003e.\n\n\n### Manually\n\n1. Download all the files in the YYAsyncLayer subdirectory.\n2. Add the source files to your Xcode project.\n3. Import `YYAsyncLayer.h`.\n\n\nDocumentation\n==============\nFull API documentation is available on [CocoaDocs](http://cocoadocs.org/docsets/YYAsyncLayer/).\u003cbr/\u003e\nYou can also install documentation locally using [appledoc](https://github.com/tomaz/appledoc).\n\n\nRequirements\n==============\nThis library requires `iOS 6.0+` and `Xcode 8.0+`.\n\n\nLicense\n==============\nYYAsyncLayer is provided under the MIT license. See LICENSE file for details.\n\n\n\n\n\u003cbr/\u003e\u003cbr/\u003e\n---\n中文介绍\n==============\niOS 异步绘制与显示的工具类。\u003cbr/\u003e\n(该工具是从 [YYText](https://github.com/ibireme/YYText) 提取出来的独立组件)\n\n\n简单用法\n==============\n\n```objc\n@interface YYLabel : UIView\n@property NSString *text;\n@property UIFont *font;\n@end\n\n@implementation YYLabel\n\n- (void)setText:(NSString *)text {\n    _text = text.copy;\n    [[YYTransaction transactionWithTarget:self selector:@selector(contentsNeedUpdated)] commit];\n}\n\n- (void)setFont:(UIFont *)font {\n    _font = font;\n    [[YYTransaction transactionWithTarget:self selector:@selector(contentsNeedUpdated)] commit];\n}\n\n- (void)layoutSubviews {\n    [super layoutSubviews];\n    [[YYTransaction transactionWithTarget:self selector:@selector(contentsNeedUpdated)] commit];\n}\n\n- (void)contentsNeedUpdated {\n    // do update\n    [self.layer setNeedsDisplay];\n}\n\n#pragma mark - YYAsyncLayer\n\n+ (Class)layerClass {\n    return YYAsyncLayer.class;\n}\n\n- (YYAsyncLayerDisplayTask *)newAsyncDisplayTask {\n    \n    // capture current state to display task\n    NSString *text = _text;\n    UIFont *font = _font;\n    \n    YYAsyncLayerDisplayTask *task = [YYAsyncLayerDisplayTask new];\n    task.willDisplay = ^(CALayer *layer) {\n        //...\n    };\n    \n    task.display = ^(CGContextRef context, CGSize size, BOOL(^isCancelled)(void)) {\n        if (isCancelled()) return;\n        NSArray *lines = CreateCTLines(text, font, size.width);\n        if (isCancelled()) return;\n        \n        for (int i = 0; i \u003c lines.count; i++) {\n            CTLineRef line = line[i];\n            CGContextSetTextPosition(context, 0, i * font.pointSize * 1.5);\n            CTLineDraw(line, context);\n            if (isCancelled()) return;\n        }\n    };\n    \n    task.didDisplay = ^(CALayer *layer, BOOL finished) {\n        if (finished) {\n            // finished\n        } else {\n            // cancelled\n        }\n    };\n    \n    return task;\n}\n@end\n```\n\n安装\n==============\n\n### CocoaPods\n\n1. 在 Podfile 中添加 `pod 'YYAsyncLayer'`。\n2. 执行 `pod install` 或 `pod update`。\n3. 导入 \\\u003cYYAsyncLayer/YYAsyncLayer.h\\\u003e。\n\n\n### Carthage\n\n1. 在 Cartfile 中添加 `github \"ibireme/YYAsyncLayer\"`。\n2. 执行 `carthage update --platform ios` 并将生成的 framework 添加到你的工程。\n3. 导入 \\\u003cYYAsyncLayer/YYAsyncLayer.h\\\u003e。\n\n\n### 手动安装\n\n1. 下载 YYAsyncLayer 文件夹内的所有内容。\n2. 将 YYAsyncLayer 内的源文件添加(拖放)到你的工程。\n3. 导入 `YYAsyncLayer.h`。\n\n\n文档\n==============\n你可以在 [CocoaDocs](http://cocoadocs.org/docsets/YYAsyncLayer/) 查看在线 API 文档，也可以用 [appledoc](https://github.com/tomaz/appledoc) 本地生成文档。\n\n\n系统要求\n==============\n该项目最低支持 `iOS 6.0` 和 `Xcode 8.0`。\n\n\n许可证\n==============\nYYAsyncLayer 使用 MIT 许可证，详情见 LICENSE 文件。\n\n相关文章\n==============\n[iOS 保持界面流畅的技巧\n](https://blog.ibireme.com/2015/11/12/smooth_user_interfaces_for_ios/) \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibireme%2FYYAsyncLayer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibireme%2FYYAsyncLayer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibireme%2FYYAsyncLayer/lists"}