2017-08-17 36 views
0

如何使控件ASdisplayNode與單元格高度一致?控制ASdisplayNode高度與單元格高度一致

- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize{ 
NSMutableArray *rightArray =[[NSMutableArray alloc]initWithObjects:_titleNode, _descNode,nil]; 
[rightArray addObjectsFromArray:_replayNodes]; 
ASStackLayoutSpec *verStackLayout = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical spacing:8 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStart children:rightArray]; 
verStackLayout.style.flexGrow = YES; 
verStackLayout.style.flexShrink = YES; 
self.dateNode.style.preferredSize = CGSizeMake(130 ,50);//How high is the height of cell? 
self.dateNode.style.flexShrink = YES; 
ASStackLayoutSpec *horStackLayout = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal spacing:10 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStart children:@[self.dateNode,verStackLayout]]; 
horStackLayout.style.flexShrink = YES; 
return horStackLayout; 
} 

enter image description here

+0

看看這個例子:https://github.com/TextureGroup/Texture/tree/master/examples/VerticalWithinHorizo​​ntalScrolling – Bimawa

+0

謝謝你,但它不是我的問題。我的線路因ASTableNode單元的高度而異。這不是一個固定的價值。 – freda

回答

0

試試這個代碼,並告訴你得到了什麼?

- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize{ 
NSMutableArray *rightArray =[[NSMutableArray alloc]initWithObjects:_titleNode, _descNode,nil]; 
[rightArray addObjectsFromArray:_replayNodes]; 
ASStackLayoutSpec *verStackLayout = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical spacing:8 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStretch children:rightArray]; 
verStackLayout.style.flexGrow = YES; 
verStackLayout.style.flexShrink = YES; 
self.dateNode.style.flexShrink = YES; 
ASStackLayoutSpec *horStackLayout = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal spacing:10 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStretch children:@[self.dateNode,verStackLayout]]; 
horStackLayout.style.flexShrink = YES; 
horStackLayout.style.flexGrow = YES; 
horStackLayout.style.alignSelf = ASStackLayoutAlignItemsStretch; 
return horStackLayout; 
} 
+0

self.dateNode不是首選大小。它無法顯示。 – freda

+0

無法計算節點的大小:constrainedSize是無限的,並且節點不覆蓋-calculateSizeThatFits:或指定preferredSize。嘗試設置style.preferredSize。 Node:<< ASDisplayNode:0x7fd9f270a280> alpha:1.00 isLayerBacked:1 frame:{{0,0},{0,0}}(null)> – freda

+0

@freda可以分享一個簡單的例子,我會嘗試做你的任務。 – Bimawa