Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

YYAsyncLayer

iOS utility classes for asynchronous rendering and display.

Subscribe to updates I use YYAsyncLayer


Statistics on YYAsyncLayer

Number of watchers on Github 391
Number of open issues 9
Average time to close an issue 9 days
Main language Objective-C
Open pull requests 2+
Closed pull requests 0+
Last commit about 2 years ago
Repo Created almost 4 years ago
Repo Last Updated over 1 year ago
Size 39 KB
Organization / Authoribireme
Latest Release1.0
Contributors1
Page Updated
Do you use YYAsyncLayer? Leave a review!
View open issues (9)
View YYAsyncLayer activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating YYAsyncLayer for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

YYAsyncLayer

License MIT  Carthage compatible  CocoaPods  CocoaPods  Support  Build Status

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

  1. Add pod 'YYAsyncLayer' to your Podfile.
  2. Run pod install or pod update.
  3. Import <YYAsyncLayer/YYAsyncLayer.h>.

Carthage

  1. Add github "ibireme/YYAsyncLayer" to your Cartfile.
  2. Run carthage update --platform ios and add the framework to your project.
  3. Import <YYAsyncLayer/YYAsyncLayer.h>.

Manually

  1. Download all the files in the YYAsyncLayer subdirectory.
  2. Add the source files to your Xcode project.
  3. 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

  1. Podfile pod 'YYAsyncLayer'
  2. pod install pod update
  3. <YYAsyncLayer/YYAsyncLayer.h>

Carthage

  1. Cartfile github "ibireme/YYAsyncLayer"
  2. carthage update --platform ios framework
  3. <YYAsyncLayer/YYAsyncLayer.h>
  1. YYAsyncLayer
  2. YYAsyncLayer ()
  3. YYAsyncLayer.h

============== CocoaDocs API appledoc

============== iOS 6.0 Xcode 8.0

============== YYAsyncLayer MIT LICENSE

============== iOS

YYAsyncLayer open issues Ask a question     (View All Issues)
  • almost 3 years CALayer内部没有属性的疑问
  • about 3 years 关于最大线程数
  • about 3 years 求解一些关于CALayer高性能的文字或代码
  • about 3 years 问题:我在我的属性文本中用到了YYAsyncLayer 可是 滑动很快的时候 文字出现了拉伸或者缩小变形的情况
  • over 3 years [self setNeedsDisplay] 无效
  • over 3 years CALayer 内部并没有属性 疑问
YYAsyncLayer open pull requests (View All Pulls)
  • Update .gitignore
  • Add syntax highlighting to readme.
YYAsyncLayer list of languages used
YYAsyncLayer latest release notes
1.0 First release, stable API
  • Swift api compatibility
0.9.0 Initial

Initial commit

Other projects in Objective-C