Swift CustomView,在layoutSubviews中具有手动布局我应该覆盖systemLayoutSizeFitting,internalContentSize吗?

问题描述

我有

public override func layoutSubviews() {
        super.layoutSubviews()
        updateMySubviews()
 }

然后

private func updateMySubviews(reset: Bool = false) {
        buttons.forEach { $0.removeFromSuperview() }
        
        if reset {
            buttons.removeAll()
            models.forEach { tag in
                buttons.append(createBubbleButton(with: model))
            }
        }

        var offsetPoint = CGPoint(x: contentOffset,y: contentOffset)
        
        buttons.forEach { button in

            if button.frame.width + offsetPoint.x + itemOffset >= bounds.width {
                offsetPoint = CGPoint(
                    x: contentOffset,y: offsetPoint.y + Constants.itemHeight + itemOffset
                )
            }
            
            button.frame = CGRect(origin: offsetPoint,size: button.frame.size)
            addSubview(button)
            offsetPoint = CGPoint(x: offsetPoint.x + button.frame.size.width + itemOffset,y: offsetPoint.y)
        }
        
        height = (buttons.count > 0) ? offsetPoint.y + Constants.itemHeight + contentOffset : 0
        
        heightConstraint.constant = height
        invalidateIntrinsicContentSize()
    }

我也有

 public override var intrinsicContentSize: CGSize {
        return CGSize(width: UIView.noIntrinsicmetric,height: height)
    }

但是当我尝试此视图时,

headerView.systemLayoutSizefitting(UIView.layoutFittingCompressedSize)

我总是得到(0,0) / 我应该重写systemLayoutSizefitting以便我的CustomView返回正确的值吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)