iOS使用AsyncDisplayKit
2017-07-09 本文已影响130人
Hither
-
这个库就是一种复杂界面依旧可以保持界面流畅性的库,具体用法 其实和UIKit里面的用法差不多,不同的地方在于他独特的约束方式;
-
约束:
水平约束 和 垂直约束 ,在两个基础上,可以自由组合一些其他的约束,比如 中心约束、插入约束、绝对约束等,具体要使用到那些约束,看需求而定;
- 在这约束中,有两个轴,一个主轴,一个十字轴;
direction:主轴的方向,有两个可选值:
纵向:ASStackLayoutDirectionVertical
横向:ASStackLayoutDirectionHorizontal
spacing: 主轴上视图排列的间距,比如有四个视图,那么它们之间的存在三个间距值都应该是spacing
justifyContent: 主轴上的排列方式,有五个可选值:
ASStackLayoutJustifyContentStart 从前往后排列
ASStackLayoutJustifyContentCenter 居中排列
ASStackLayoutJustifyContentEnd 从后往前排列
ASStackLayoutJustifyContentSpaceBetween 间隔排列,两端无间隔
ASStackLayoutJustifyContentSpaceAround 间隔排列,两端有间隔
alignItems: 交叉轴上的排列方式,有五个可选值:
ASStackLayoutAlignItemsStart 从前往后排列
ASStackLayoutAlignItemsEnd 从后往前排列
ASStackLayoutAlignItemsCenter 居中排列
ASStackLayoutAlignItemsStretch 拉伸排列
ASStackLayoutAlignItemsBaselineFirst 以第一个文字元素基线排列(主轴是横向才可用)
ASStackLayoutAlignItemsBaselineLast 以最后一个文字元素基线排列(主轴是横向才可用)
children: 包含的视图。数组内元素顺序同样代表着布局时排列的顺序,所以需要注意
主轴的方向设置尤为重要,如果主轴设置的是 ASStackLayoutDirectionVertical, 那么 justifyContent 各个参数的意义就是:
ASStackLayoutJustifyContentStart 从上往下排列
ASStackLayoutJustifyContentCenter 居中排列
ASStackLayoutJustifyContentEnd 从下往上排列
ASStackLayoutJustifyContentSpaceBetween 间隔排列,两端无间隔
ASStackLayoutJustifyContentSpaceAround 间隔排列,两端有间隔
alignItems 就是:
ASStackLayoutAlignItemsStart 从左往右排列
ASStackLayoutAlignItemsEnd 从右往左排列
ASStackLayoutAlignItemsCenter 居中排列
ASStackLayoutAlignItemsStretch 拉伸排列
ASStackLayoutAlignItemsBaselineFirst 无效
ASStackLayoutAlignItemsBaselineLast 无效
举个例子:
//Direction: 元素排列的方向 (都是和主轴平行)
ASStackLayoutSpec *comicNameStack = [ASStackLayoutSpec
stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal
spacing:0
justifyContent:ASStackLayoutJustifyContentStart
alignItems:ASStackLayoutAlignItemsStart
children:@[_comicNameNode]];
添加MJRefresh:
-(void)configRefresh{
__weak __typeof(self) weakSelf= self;
self.mainTableNode.view.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
[self.mainTableNode.view.mj_header endRefreshing];
self.currentPage = 0;
[_models removeAllObjects];
if(![self hasMoreData]){// 无数据显示
self.mainTableNode.view.mj_footer.state = MJRefreshStateNoMoreData;
}else{
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.mainTableNode reloadData];
});
}
}];
self.mainTableNode.view.mj_footer=[MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
if(![self hasMoreData]){// 无数据显示
self.mainTableNode.view.mj_footer.state = MJRefreshStateNoMoreData;
}else{
[self.mainTableNode.view.mj_footer endRefreshing];
}
}];
}

具体的使用 我网上找了个例子并扩展了一些东西,大家可以相互学习;