微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。