【发布时间】:2023-03-30 01:44:02
【问题描述】:
我有一段代码可以并排显示图像视图和 UILabel。它根据提供的约束按预期显示,但控制台中有很多警告
这是错误
[LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x6000003d0190 V:|-(0)-[UIImageView:0x7faa7401b940] (active, names: '|':Movies_TODO.MovieViewCell:0x7faa7402caa0'custom' )>",
"<NSLayoutConstraint:0x6000003d05a0 UIImageView:0x7faa7401b940.bottom == Movies_TODO.MovieViewCell:0x7faa7402caa0'custom'.bottom (active)>",
"<NSLayoutConstraint:0x6000003d0640 UIImageView:0x7faa7401b940.height == 100 (active)>",
"<NSLayoutConstraint:0x6000003e7070 'UIView-Encapsulated-Layout-Height' Movies_TODO.MovieViewCell:0x7faa7402caa0'custom'.height == 100.5 (active)>"
)
将尝试通过打破约束来恢复
这是我的一段代码
self.addSubview(movieImageView)
self.addSubview(titleLabel)
movieImageView.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
movieImageView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
movieImageView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
movieImageView.widthAnchor.constraint(equalToConstant: 100).isActive = true
movieImageView.heightAnchor.constraint(equalToConstant: 100).isActive = true
titleLabel.leadingAnchor.constraint(equalTo: movieImageView.trailingAnchor, constant: 20).isActive = true
titleLabel.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
titleLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
titleLabel.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
【问题讨论】:
标签: ios swift iphone autolayout