Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Layout Constraints #5

Open
kayloehmann opened this issue Jan 6, 2021 · 0 comments
Open

Issue with Layout Constraints #5

kayloehmann opened this issue Jan 6, 2021 · 0 comments

Comments

@kayloehmann
Copy link

Hi,

i have an issue with the following code in TimelineFeed:

	private func addCard(_ card: TimelineCard) {
		self.card = card
        
		card.reload()
		
		card.frame = CGRect(origin: CGPoint(x: 0.0, y: (headerView?.frame.origin.y ?? 0.0) + (headerView?.frame.height ?? 0.0)), size: card.bounds.size)
		
		self.insertSubview(card, at: subviews.count)
        
		let constraints: [NSLayoutConstraint] = [
			NSLayoutConstraint(item: headerView ?? self, attribute: headerView != nil ? .bottom : .top, relatedBy: .equal, toItem: card, attribute: .top, multiplier: 1, constant: 1),
			NSLayoutConstraint(item: self, attribute: .leading, relatedBy: .equal, toItem: card, attribute: .leading, multiplier: 1, constant: 1),
			NSLayoutConstraint(item: self, attribute: .trailing, relatedBy: .equal, toItem: card, attribute: .trailing, multiplier: 1, constant: 1),
			NSLayoutConstraint(item: self, attribute: .bottom, relatedBy: .equal, toItem: card, attribute: .bottom, multiplier: 1, constant: bottomPadding),
			NSLayoutConstraint(item: card, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: card.bounds.size.height)
		]

		constraints.forEach { $0.isActive = true }
	}

It generates the following error messages:

2021-01-06 18:07:02.636373+0100 EinfachLeichterLeben[20536:946407] [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:0x60000250d630 _TtC20EinfachLeichterLebenP33_CD7A8457D9CF40B1C3DACE082F374E5216TimelineFeedCell:0x7fa758d40cc0'TimelineFeedCell'.top == EinfachLeichterLeben.TimelineCard:0x7fa758d414a0.top + 1 (active)>",
"<NSLayoutConstraint:0x60000250d270 V:[EinfachLeichterLeben.TimelineCard:0x7fa758d414a0]-(20)-| (active, names: '|':_TtC20EinfachLeichterLebenP33_CD7A8457D9CF40B1C3DACE082F374E5216TimelineFeedCell:0x7fa758d40cc0'TimelineFeedCell' )>",
"<NSLayoutConstraint:0x60000250f160 EinfachLeichterLeben.TimelineCard:0x7fa758d414a0.height == 192 (active)>",
"<NSLayoutConstraint:0x600002574870 'UIView-Encapsulated-Layout-Height' _TtC20EinfachLeichterLebenP33_CD7A8457D9CF40B1C3DACE082F374E5216TimelineFeedCell:0x7fa758d40cc0'TimelineFeedCell'.height == 211.333 (active)>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60000250f160 EinfachLeichterLeben.TimelineCard:0x7fa758d414a0.height == 192 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

Latest Xcode, iOS 13 Target

Do you have any ideas, what i could do? It think it also breaks the delegate methods for the header and the card elements.

Thanks! Kay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant