2016-12-30 123 views
1

简单的细胞,我试图建立与Facebook的AsyncDisplayKit下面的设计,我必须建立细胞和TableHeaderView问题。与AsyncDisplayKit布局

设计:

细胞:

所以每个单元都有一个ASImageNode,并具有以下布局一个ASEditableTextNode

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec { 
    var cellChildren = [ASLayoutElement]() 

    let iconTextfieldStack = ASStackLayoutSpec.horizontal() 
    iconTextfieldStack.alignItems = .center 
    iconTextfieldStack.justifyContent = .start 
    iconTextfieldStack.style.flexShrink = 1.0 
    iconTextfieldStack.style.flexGrow = 1.0 

    _iconImageView.style.preferredSize = CGSize(width: 30, height: 30) 
    cellChildren.append(ASInsetLayoutSpec(insets: UIEdgeInsetsMake(10, 10, 10, 10), child: _iconImageView)) 

    _textField.style.spacingBefore = 10 
    cellChildren.append(ASInsetLayoutSpec(insets: UIEdgeInsetsMake(0, 0, 0, 10), child: _textField)) 

    iconTextfieldStack.children = cellChildren 


    return ASInsetLayoutSpec(insets: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0), child: iconTextfieldStack) 
} 

结果看起来像这个:

正如可以看到第三行ASEditableTextNode超过细胞宽度(第一个问题)。另一件事是ASEditableTextNode不扩展其高度(和单元格高度)以显示ASEditableTextNode文本的行。另外我得到这个警告:

-[UIWindow endDisablingInterfaceAutorotationAnimated:] called on <UIRemoteKeyboardWindow: 0x1024c9c00; frame = (0 0; 375 667); opaque = NO; autoresize = W+H; layer = <UIWindowLayer: 0x17022e4c0>> without matching -beginDisablingInterfaceAutorotation. Ignoring. 

有没有办法做到这一点?

回答

1

感谢名单,以松弛组我已经改变了功能,解决了这个问题:

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec { 
    var cellChildren = [ASLayoutElement]() 

    let iconTextfieldStack = ASStackLayoutSpec.horizontal() 
    iconTextfieldStack.alignItems = .center 
    iconTextfieldStack.justifyContent = .start 
    iconTextfieldStack.style.flexShrink = 1.0 
    iconTextfieldStack.style.flexGrow = 1.0 

    _iconImageView.style.preferredSize = CGSize(width: 30, height: 30) 
    _iconImageView.style.alignSelf = .start 
    cellChildren.append(ASInsetLayoutSpec(insets: UIEdgeInsetsMake(10, 10, 10, 10), child: _iconImageView)) 

    _textField.style.spacingBefore = 10 

    let textInset = ASInsetLayoutSpec(insets: UIEdgeInsetsMake(10, 0, 10, 10), child: _textField) 
    textInset.style.flexShrink = 1.0 

    cellChildren.append(textInset) 

    iconTextfieldStack.children = cellChildren 


    return iconTextfieldStack 
} 

主要的关键是要增加flexShrink到文本框的ASInsetLayoutSpec