자동 레이아웃 내보기의 높이를 설정하려면 NSLayoutConstraint
코드로 내보기 및이 같은 이상한 오류가 있습니다 : 324.867
같은보기의 높이를 설정할 때 사용합니다. 오류 Unable to simultaneously satisfy constraints
가 발생합니다.분수를 사용할 때 [LayoutConstraints] 오류가 발생합니다. 그러나 그 숫자를 반올림 할 때. 오류가 사라졌습니다
하지만 반올림 한 경우 324.867
에서 324
입니다. 오류가 사라졌습니다.
왜 그런 일이 일어날 수 있습니까?
이
내 코드입니다 : 내 topicTitle 높이 (표에 의해 자동으로 내 수퍼 년대의 설정 높이를 원하는 때문에 가let estimateSizeOfTopic = CGSize(width: self.frame.width - 10.0, height: 1000.0)
let attributeOfTopic = [NSFontAttributeName: UIFont.systemFont(ofSize: 14)]
let estimateHeight = NSString(string: topicTitle.text!).boundingRect(with: estimateSizeOfTopic, options: .usesLineFragmentOrigin, attributes: attributeOfTopic, context: nil).height
NSLayoutConstraint(item: topicTitle, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: estimateHeight).isActive = true
NSLayoutConstraint(item: topicTitle, attribute: .top, relatedBy: .equal, toItem: superView, attribute: .top, multiplier: 1.0, constant: 5.0).isActive = true
NSLayoutConstraint(item: topicTitle, attribute: .left, relatedBy: .equal, toItem: superView, attribute: .left, multiplier: 1.0, constant: 5.0).isActive = true
NSLayoutConstraint(item: topicTitle, attribute: .right, relatedBy: .equal, toItem: superView, attribute: .right, multiplier: 1.0, constant: -5.0).isActive = true
NSLayoutConstraint(item: topicTitle, attribute: .bottom, relatedBy: .equal, toItem: superView, attribute: .bottom, multiplier: 1.0, constant: -5.0).isActive = true
이 // 내 수퍼는 아무 제약이없는 ... 나는 그런 식으로 코딩 셀 자동 크기 조정보기
첫 번째 제약 조건에서 오류가 발생합니다.
//If I use this line of code. It raise an error
NSLayoutConstraint(item: topicTitle, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: estimateHeight).isActive = true
//If I use this line of code instead. The error is gone
NSLayoutConstraint(item: topicTitle, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: round(estimateHeight)).isActive = true
나는 둥근 내
estimateHeight
내가 반올림하지 않은 경우,이 오류 .. 를 제기하지만 오류가의 영감 때문이다. 이러한 오류의 수학 (문자)를 추가하기 때문에
[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:0x608000484560 UITextView:0x7f9049080c00'It is a long established ...'.height == 324.867 (active)>",
"<NSLayoutConstraint:0x608000285280 V:|-(5)-[UITextView:0x7f9049080c00'It is a long established ...'] (active, names: '|':SatacusWorld.PostViewCell:0x7f9049096a00'postIdentifier')>",
"<NSLayoutConstraint:0x60800029fe50 UITextView:0x7f9049080c00'It is a long established ...'.bottom == SatacusWorld.PostViewCell:0x7f9049096a00'postIdentifier'.bottom - 5 (active)>",
"<NSLayoutConstraint:0x60800029fcc0 'UIView-Encapsulated-Layout-Height' SatacusWorld.PostViewCell:0x7f9049096a00'postIdentifier'.height == 334.8 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x608000484560 UITextView:0x7f9049080c00'It is a long established ...'.height == 324.867 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.