我正在尝试为 AsyncDisplayKit 中的节点设置布局以进行 userProfile 设置,但没有得到所需的结果。
- 我有一个 userProfile 图像
- 用户名标签
- 设置按钮
- 帖子、评论和点赞按钮 我想将所有节点设置为水平和垂直对齐
这是我在layoutSpecThatFits
方法中的代码
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
photoNode.style.preferredSize = CGSize(width: ImageSize, height: ImageSize)
settingButton.style.preferredSize = CGSize(width: 100, height: 50)
label.style.preferredSize = CGSize(width: 100, height: 50)
editbutton.style.preferredSize = CGSize(width: 120, height: 40)
settingButton.style.alignSelf = .stretch
let layout = ASStackLayoutSpec.horizontal()
layout.alignItems = .center
layout.justifyContent = .spaceAround
layout.spacing = 10
layout.children = [photoNode,settingButton]
let settingButtonStackLocation = ASStackLayoutSpec(direction: .vertical,
spacing: 15,
justifyContent: .center,
alignItems: .center,
children: [layout,label,editbutton])
settingButtonStackLocation.style.flexShrink = 1.0
settingButtonStackLocation.style.flexGrow = 1.0
let insets = UIEdgeInsets(top: 50, left: 30, bottom: 0, right: 30)
let inset = ASInsetLayoutSpec(insets: insets, child: settingButtonStackLocation)
let horizontalButtonsStack = ASStackLayoutSpec.horizontal()
horizontalButtonsStack.children = [postsButton,bucketButton,likesButton]
horizontalButtonsStack.spacing = 20
let verticalStack = ASStackLayoutSpec.vertical()
verticalStack.children = [inset,horizontalButtonsStack]
verticalStack.spacing = 10
let buttonInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
let buttonWithInsets = ASInsetLayoutSpec(insets: buttonInsets, child: verticalStack)
let horizontalFollowersStack = ASStackLayoutSpec.horizontal()
horizontalFollowersStack.children = [followersButton,followingButton]
horizontalFollowersStack.spacing = 10
let verticalFollowers = ASStackLayoutSpec.vertical()
verticalFollowers.children = [buttonWithInsets,horizontalFollowersStack]
verticalFollowers.spacing = 10
verticalFollowers.alignItems = .center
let followersInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
let followersWithInsets = ASInsetLayoutSpec(insets: followersInsets, child: verticalFollowers)
return followersWithInsets
}