Pracujem na vytvorenie vlastného zoznamu bunky (zber zobraziť zoznam bunky), založené na tomto článku. Som manuálne pridať výška zobraziť v bunke, ale vidím, varovania nižšie v konzole Xcode, a nie ste si istí, ktorú časť opraviť.
[LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x281209220 h=--& v=--& liveTest.LiveChannelContentView:0x128c13430.height == 44 (active)>",
"<NSLayoutConstraint:0x2812371b0 UIView:0x128c136b0.height == 60 (active)>",
"<NSLayoutConstraint:0x2812372a0 V:|-(0)-[UIView:0x128c136b0] (active, names: '|':liveTest.LiveChannelContentView:0x128c13430 )>",
"<NSLayoutConstraint:0x2812372f0 UIView:0x128c136b0.bottom == liveTest.LiveChannelContentView:0x128c13430.bottom (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x2812371b0 UIView:0x128c136b0.height == 60 (active)>
Kód nižšie je, kde som si toto chybové hlásenie.
class LiveChannelContentView: UIView, UIContentView {
let contentsView = UIView()
lazy var titleLabel: UILabel = {
let label = UILabel()
label.text = ""
return label
}()
lazy var statusLabel: UILabel = {
let label = UILabel()
label.text = ""
return label
}()
lazy var symbolImageView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
return imageView
}()
var liveEvent: LiveEvent?
init(configuration: LiveChannelContentConfiguration) {
// Custom initializer implementation here.
super.init(frame: .zero)
print("this is the view height: \(self.bounds.height)") // -> I get 0.0 in here
setupAllViews()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupAllViews() {
addSubview(contentsView)
contentsView.addSubview(symbolImageView)
contentsView.addSubview(indicator)
contentsView.addSubview(titleLabel)
contentsView.addSubview(statusLabel)
contentsView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
contentsView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor),
contentsView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor),
contentsView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor),
contentsView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor),
contentsView.heightAnchor.constraint(equalToConstant: 60)
])
contentsView.backgroundColor = .yellow
symbolImageView.centerY(leading: contentsView.leadingAnchor, trailing: nil, parent: contentsView, paddingLeft: 0, paddingRight: 0, size: CGSize(width: 50, height: 50))
indicator.centerY(leading: contentsView.leadingAnchor, trailing: nil, parent: contentsView, paddingLeft: 0, paddingRight: 0, size: CGSize(width: 50, height: 50))
titleLabel.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
titleLabel.leadingAnchor.constraint(equalTo: symbolImageView.trailingAnchor, constant: 8),
titleLabel.topAnchor.constraint(equalTo: symbolImageView.topAnchor),
titleLabel.trailingAnchor.constraint(equalTo: contentsView.trailingAnchor)
])
statusLabel.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
statusLabel.leadingAnchor.constraint(equalTo: titleLabel.leadingAnchor),
statusLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor),
statusLabel.trailingAnchor.constraint(equalTo: titleLabel.trailingAnchor)
])
print("this is the view after setup: \(self.bounds.height)") // I also get 0.0 in here
}
}
Takže, ak chcete objasniť, kde LiveChannelContentView je, len som sa pridať na žltom pozadí sa na zobrazenie. Tam sú dve veci, ja to nechápem. Po prvé, aj Xcode mi hovorí, že
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x2812371b0 UIView:0x128c136b0.height == 60 (active)>
keď som si screenshot z aplikácie a opatrenia na žltom pozadí UIView výšky, to je ešte v 60. Myslel som, že lámanie obmedzenia znamená, že pomocou iných výška prekážky namiesto 60, ale je to zle?
Ďalšia vec je, že som bol zvedavý, kde
"<NSAutoresizingMaskLayoutConstraint:0x281209220 h=--& v=--& liveTest.LiveChannelContentView:0x128c13430.height == 44 (aktívne)>" používa sa v mojom kóde. Hľadal som súbor obsahuje
44
v mojom priestoru, ale som nič.
Naozaj nie je istý, ale myslel som si, výška 44 a 60 je aplikovaný na rovnakej UIView a Xcode zbavil 60 výška kotvy alebo niečo. Avšak, keď som odstrániť výška kotvy pre contentsView, contentsView.heightAnchor.constraint(equalToConstant: 60)
aplikácia havaroval ako nižšie.
Tiež som sa snažil odstránením hornej alebo dolnej časti kotvy z contentsView, ale tiež drvené aplikácie.
contentsView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor),
alebo
contentsView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor),
Tak môže mi niekto povedať, ktorý obmedzenia by som opraviť zbaviť waring, prosím?