Graver

作者: Code_人生 | 来源:发表于2019-10-08 16:43 被阅读0次

    美团开源Graver框架:用“雕刻”诠释iOS端UI界面的高效渲染

    一、attributedItem

    - (void)basicUseDemo
    {
        //WMMutableAttributedItem : 视图绘制单元(自己拼接的!)
        WMMutableAttributedItem *text1 = [WMMutableAttributedItem itemWithText:@"Graver是一种高效的UI渲染框架。"];
        [text1 setFont:[UIFont systemFontOfSize:18]];
        [text1 setColor:WMGHEXCOLOR(0xff8205)];
        
        //绘制 Item
        WMGMixedView *view = [[WMGMixedView alloc] initWithFrame:CGRectZero];
        view.attributedItem = text1;
        
        CGSize size = [text1.resultString wmg_sizeConstrainedToWidth:self.view.frame.size.width - 20];
        view.frame = CGRectMake(10, 10, size.width, size.height);
        [_scrollView addSubview:view];
    }
    

    点击attributedItem

    - (void)setAttributedItem:(WMMutableAttributedItem *)attributedItem
    {
        if (_attributedItem != attributedItem)
        {
            _attributedItem = attributedItem;
            
            //异步的操作!!!
            [self setNeedsDisplayAsync];
            
            _pendingAttachmentUpdates = YES;
        }
    }
    

    点击setNeedsDisplayAsync->WMGAsyncDrawView.m

    - (void)setNeedsDisplayAsync
    {
        self.contentsChangedAfterLastAsyncDrawing = YES;
        //需要更新
        [self setNeedsDisplay];
    }
    

    点击setNeedsDisplay

    - (void)setNeedsDisplay
    {
        [self.layer setNeedsDisplay];
    }
    

    点击setNeedsDisplay->WMGAsyncDrawLayer.m

    - (void)setNeedsDisplay
    {
        [self increaseDrawingCount];
        [super setNeedsDisplay];
    }
    

    [super setNeedsDisplay]; CALayer调用setNeedsDisplay

    二、graver接管异步绘制

    相关文章

      网友评论

          本文标题:Graver

          本文链接:https://www.haomeiwen.com/subject/jbzpuctx.html