首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIViewRepresentable保持白色

UIViewRepresentable保持白色
EN

Stack Overflow用户
提问于 2022-03-05 11:43:50
回答 1查看 131关注 0票数 0

我有一个非常基本的设置:

代码语言:javascript
复制
struct ConversationChatMessagesWrapper: UIViewRepresentable {
    private let view = ConversationChatViewWithSendMessage()

    func makeUIView(context _: Context) -> ConversationChatViewWithSendMessage {
        view
    }

    func updateUIView(
        _: ConversationChatViewWithSendMessage,
        context _: Context
    ) {}
}


class ConversationChatViewWithSendMessage: UIView {
    @available(*, unavailable)
    required init?(coder _: NSCoder) {
        fatalError("Not used")
    }

    init() {
        super.init(frame: .zero)

        translatesAutoresizingMaskIntoConstraints = false

        backgroundColor = .red

        let otherView = UIView()

        otherView.backgroundColor = .blue
        otherView.translatesAutoresizingMaskIntoConstraints = false

        addSubview(otherView)

        otherView.topAnchor.constraint(equalTo: topAnchor).isActive = true
        otherView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
        otherView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
        otherView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
    }
}

我已经有一段时间没有使用UIKit了,但是我认为它应该看到一个蓝色的屏幕,或者至少是一个红色的屏幕,但是我的屏幕仍然是白色的。当我删除将otherView添加到ConversationChatViewWithSendMessage的调用时,我会看到一个蓝色的屏幕,所以在添加otherView时出现了一些问题,但是我看不到什么。我甚至在Storyboard中复制了这个设置,它运行得很好。

有什么建议吗?

这是Xcode的屏幕截图,警告声明:

Position and size are ambigious

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-05 11:53:50

super.init之后删除这一行。

代码语言:javascript
复制
translatesAutoresizingMaskIntoConstraints = false
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71361876

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档