프로젝트
GitHub에서 보기
ibireme/YYAsyncLayer
소개
비동기 렌더링 및 표시를 위한 iOS 유틸리티 클래스입니다.
디자인 및 미디어측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalYYAsyncLayer
iOS utility classes for asynchronous rendering and display.
(It was used by YYText)
Simple Usage
@interface YYLabel : UIView
@property NSString *text;
@property UIFont *font;
@end
@implementation YYLabel
- (void)setText:(NSString *)text {
_text = text.copy;
[[YYTransaction transactionWithTarget:self selector:@selector(contentsNeedUpdated)] commit];
}
- (void)setFont:(UIFont *)font {
_font = font;
[[YYTransaction transactionWithTarget:self selector:@selector(contentsNeedUpdated)] commit];
}
- (void)layoutSubviews {
[super layoutSubviews];
[[YYTransaction transactionWithTarget:self selector:@selector(contentsNeedUpdated)] commit];
}
- (void)contentsNeedUpdated {
// do update
[self.layer setNeedsDisplay];
}
#pragma mark - YYAsyncLayer
+ (Class)layerClass {
return YYAsyncLayer.class;
}
- (YYAsyncLayerDisplayTask *)newAsyncDisplayTask {
// capture current state to display task
NSString *text = _text;
UIFont *font = _font;
YYAsyncLayerDisplayTask *task = [YYAsyncLayerDisplayTask new];
task.willDisplay = ^(CALayer *layer) {
//...
};
task.display = ^(CGContextRef context, CGSize size, BOOL(^isCancelled)(void)) {
if (isCancelled()) return;
NSArray *lines = CreateCTLines(text, font, size.width);
if (isCancelled()) return;
for (int i = 0; i < lines.count; i++) {
CTLineRef line = line[i];
CGContextSetTextPosition(context, 0, i * font.pointSize * 1.5);
CTLineDraw(line, context);
if (isCancelled()) return;
}
};
task.didDisplay = ^(CALayer *layer, BOOL finished) {
if (finished) {
// finished
} else {
// cancelled
}
};
return task;
}
@end
Installation
CocoaPods
- Add
pod 'YYAsyncLayer'to your Podfile. - Run
pod installorpod update. - Import <YYAsyncLayer/YYAsyncLayer.h>.
Carthage
- Add
github "ibireme/YYAsyncLayer"to your Cartfile. - Run
carthage update --platform iosand add the framework to your project. - Import <YYAsyncLayer/YYAsyncLayer.h>.
Manually
- Download all the files in the YYAsyncLayer subdirectory.
- Add the source files to your Xcode project.
- Import
YYAsyncLayer.h.
Documentation
Full API documentation is available on CocoaDocs.
You can also install documentation locally using appledoc.
Requirements
This library requires iOS 6.0+ and Xcode 8.0+.
License
YYAsyncLayer is provided under the MIT license. See LICENSE file for details.
中文介绍
iOS 异步绘制与显示的工具类。
(该工具是从 YYText 提取出来的独立组件)
简单用法
@interface YYLabel : UIView
@property NSString *text;
@property UIFont *font;
@end
@implementation YYLabel
- (void)setText:(NSString *)text {
_text = text.copy;
[[YYTransaction transactionWithTarget:self selector:@selector(contentsNeedUpdated)] commit];
}
- (void)setFont:(UIFont *)font {
_font = font;
[[YYTransaction transactionWithTarget:self selector:@selector(contentsNeedUpdated)] commit];
}
- (void)layoutSubviews {
[super layoutSubviews];
[[YYTransaction transactionWithTarget:self selector:@selector(contentsNeedUpdated)] commit];
}
- (void)contentsNeedUpdated {
// do update
[self.layer setNeedsDisplay];
}
#pragma mark - YYAsyncLayer
+ (Class)layerClass {
return YYAsyncLayer.class;
}
- (YYAsyncLayerDisplayTask *)newAsyncDisplayTask {
// capture current state to display task
NSString *text = _text;
UIFont *font = _font;
YYAsyncLayerDisplayTask *task = [YYAsyncLayerDisplayTask new];
task.willDisplay = ^(CALayer *layer) {
//...
};
task.display = ^(CGContextRef context, CGSize size, BOOL(^isCancelled)(void)) {
if (isCancelled()) return;
NSArray *lines = CreateCTLines(text, font, size.width);
if (isCancelled()) return;
for (int i = 0; i < lines.count; i++) {
CTLineRef line = line[i];
CGContextSetTextPosition(context, 0, i * font.pointSize * 1.5);
CTLineDraw(line, context);
if (isCancelled()) return;
}
};
task.didDisplay = ^(CALayer *layer, BOOL finished) {
if (finished) {
// finished
} else {
// cancelled
}
};
return task;
}
@end
安装
CocoaPods
- 在 Podfile 中添加
pod 'YYAsyncLayer'。 - 执行
pod install或pod update。 - 导入 <YYAsyncLayer/YYAsyncLayer.h>。
Carthage
- 在 Cartfile 中添加
github "ibireme/YYAsyncLayer"。 - 执行
carthage update --platform ios并将生成的 framework 添加到你的工程。 - 导入 <YYAsyncLayer/YYAsyncLayer.h>。
手动安装
- 下载 YYAsyncLayer 文件夹内的所有内容。
- 将 YYAsyncLayer 内的源文件添加(拖放)到你的工程。
- 导入
YYAsyncLayer.h。
文档
你可以在 CocoaDocs 查看在线 API 文档,也可以用 appledoc 本地生成文档。
系统要求
该项目最低支持 iOS 6.0 和 Xcode 8.0。
许可证
YYAsyncLayer 使用 MIT 许可证,详情见 LICENSE 文件。
相关文章
관련 프로젝트 살펴보기
불러오는 중…