moonlsd / TagFlowExample

Example of creating a tag flow layout for iOS
http://codentrick.com/create-a-tag-flow-layout-with-uicollectionview/
Apache License 2.0
37 stars 9 forks source link

Unable to simultaneously satisfy constraints #8

Open marcasteroid opened 5 years ago

marcasteroid commented 5 years ago

I found this issue

`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. 2019-06-06 22:28:25.696300+0200 Shared Shopping List[11996:175318] [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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSAutoresizingMaskLayoutConstraint:0x60000286f390 h=--& v=--& UIView:0x7fe4bee22240.height == 0 (active)>", "<NSLayoutConstraint:0x60000286f610 V:[UILabel:0x7fe4bee22420'Tech']-(8)-| (active, names: '|':UIView:0x7fe4bee22240 )>", "<NSLayoutConstraint:0x60000286f660 V:|-(8)-[UILabel:0x7fe4bee22420'Tech'] (active, names: '|':UIView:0x7fe4bee22240 )>" )

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x60000286f610 V:[UILabel:0x7fe4bee22420'Tech']-(8)-| (active, names: '|':UIView:0x7fe4bee22240 )>`

Can't figure out what's going on here.

marcasteroid commented 5 years ago

The problem is here

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { self.configureCell(cell: self.sizingCell!, forIndexPath: indexPath) self.sizingCell!.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize) self.sizingCell?.sizeToFit() return (self.sizingCell?.sizeThatFits(CGSize(width: (self.sizingCell?.tagName.frame.width)!, height: 32)))! }

moonlsd commented 5 years ago

The point is I am using a sizeCell to do layout calculation and return to delegate of CollectionView FlowLayout, can you check latest commit to see if update the sizingCell constraint first can help?