我有一个非常基本的设置:
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

发布于 2022-03-05 11:53:50
在super.init之后删除这一行。
translatesAutoresizingMaskIntoConstraints = falsehttps://stackoverflow.com/questions/71361876
复制相似问题