作家
登录

iOS中关于列表滚动流畅的一些探讨

作者: 来源: 2017-09-11 10:00:56 阅读 我要评论

荣幸的是,想支撑文本异步衬着也有现成的库 YYText ,下面来讲讲若何搭配它最大年夜程度知足我们如丝般顺滑的需求:

Frame 搭配异步衬着

根本思路和计算 frame 类似,只不过把体系的 boundingRectWithSize: 、 sizeWithAttributes: 换成 YYText 中的办法:

设备 frame model:

  1. //FrameYYModel.h 
  2.  
  3. @interface FrameYYModel : NSObject 
  4.  
  5. @property (assign, nonatomic, readonly) CGRect titleFrame; 
  6. @property (strong, nonatomic, readonly) YYTextLayout *titleLayout; 
  7.  
  8. @property (assign, nonatomic, readonly) CGFloat cellHeight; 
  9.  
  10. @property (strong, nonatomic) FDFeedEntity *entity; 
  11.  
  12. @end 
  13.  
  14. //FrameYYModel.m 
  15.  
  16. @implementation FrameYYModel 
  17.  
  18. - (void)setEntity:(FDFeedEntity *)entity { 
  19.     if (!entity) return
  20.      
  21.     _entity = entity; 
  22.      
  23.     CGFloat maxLayout = ([UIScreen mainScreen].bounds.size.width - 20.f); 
  24.     CGFloat space = 10.f; 
  25.     CGFloat bottom = 4.f; 
  26.      
  27.     //title 
  28.     NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:entity.title]; 
  29.     title.yy_font = Font(16.f); 
  30.     title.yy_color = [UIColor blackColor]; 
  31.      
  32.     YYTextContainer *titleContainer = [YYTextContainer containerWithSize:CGSizeMake(maxLayout, CGFLOAT_MAX)]; 
  33.     _titleLayout = [YYTextLayout layoutWithContainer:titleContainer text:title]; 
  34.      
  35.     CGFloat titleX = 10.f; 
  36.     CGFloat titleY = 10.f; 
  37.     CGSize titleSize = _titleLayout.textBoundingSize; 
  38.     _titleFrame = (CGRect){titleX,titleY,CGSizeMake(titleSize.width, titleSize.height)}; 
  39.      
  40.     //cell Height 
  41.     _cellHeight = (CGRectGetMaxY(_titleFrame) + bottom); 
  42.  
  43. @end 

UITableViewCell 处理 :

控件赋值:

  1. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 
  2.     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
  3.     if (!self) return nil; 
  4.    
  5.     YYLabel *title = [YYLabel new]; 
  6.     title.displaysAsynchronously = YES; //开启异步衬着 

      推荐阅读

      Java 9的JDK中值得期待的:不仅是模块化

    【译者注】在本文中,作者介绍了即将在9.21宣布的Java 9新特点,除了最重要的模块化以外,还涉及到编译,对象,协定,缓存等新特点,也说起了在此次版本中移除的功能,供Java爱好者浏览和>>>详细阅读


    本文标题:iOS中关于列表滚动流畅的一些探讨

    地址:http://www.17bianji.com/lsqh/37290.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)