I'm seeing an unexpected auto layout error when a cell moves off screen. Otherwise, the layout looks good, and the layout works 100% when the cell returns to the screen.
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)
(
"<NSLayoutConstraint:0x1769c940 H:|-(>=0)-[UIView:0x1769c740] (Names: '|':UIView:0x1769c6e0 )>",
"<NSLayoutConstraint:0x1769c9b0 H:[UIView:0x1769c740]-(>=0)-| (Names: '|':UIView:0x1769c6e0 )>",
"<NSLayoutConstraint:0x1769efb0 UIView:0x1769c6e0.centerX == UIView:0x1769b4b0.centerX>",
"<NSLayoutConstraint:0x1769f240 H:|-(>=5)-[UIView:0x1769c6e0] (Names: '|':UIView:0x1769b4b0 )>",
"<NSLayoutConstraint:0x1769b680 H:|-(0)-[UIView:0x1769b4b0] (Names: '|':UIView:0x17696bf0 )>",
"<NSLayoutConstraint:0x1769b6c0 H:[UIView:0x1769b4b0]-(0)-| (Names: '|':UIView:0x17696bf0 )>",
"<NSLayoutConstraint:0x17696f70 H:|-(>=0)-[UIView:0x17696bf0] (Names: '|':UIView:0x1768f710 )>",
"<NSLayoutConstraint:0x17696fc0 H:[UIView:0x17696bf0]-(>=0)-| (Names: '|':UIView:0x1768f710 )>",
"<NSAutoresizingMaskLayoutConstraint:0x176a4540 h=-&- v=-&- UIView:0x1768f710.width == SemiNodeFlowLayoutViewCell:0x17690dd0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x175a0050 h=--& v=--& H:[SemiNodeFlowLayoutViewCell:0x17690dd0(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1769c9b0 H:[UIView:0x1769c740]-(>=0)-| (Names: '|':UIView:0x1769c6e0 )>
<NSLayoutConstraint:0x1769efb0 UIView:0x1769c6e0.centerX == UIView:0x1769b4b0.centerX>
"<NSAutoresizingMaskLayoutConstraint:0x175a0050 h=--& v=--& H:[SemiNodeFlowLayoutViewCell:0x17690dd0(0)]>",
"<NSLayoutConstraint:0x1769f2b0 H:[UIView:0x1769c6e0]-(>=5)-| (Names: '|':UIView:0x1769b4b0 )>"
<NSLayoutConstraint:0x1769f2b0 H:[UIView:0x1769c6e0]-(>=5)-| (Names: '|':UIView:0x1769b4b0 )>
I can prevent these from happening by changing my constraints priority from 1000 to 999, but that has other unintended consequences, too.
Thoughts?
When a cell leaves the screen, its frame is set to CGRectZero. So if i had to guess, one of your constraints doesn't play nicely with a zero size?
-SteveZ
Hmm... many of the constraints say "you must be >= X points from each other" and, of course, CGRectZero would break those constraints. Afaik, isn't the case with UITableViewCell, so I wonder what happens differently. Keep in mind that I'm using a parent/child VC relationship... so, do the views /or VCs need to be unloaded somehow? Perhaps through removeFromParentViewController? I could also remove the constraints manually, but then the problem is cellAttached/cellDetached are called too late - after the frame is set.
Sounds great, thanks.
Bump.
Steve, I'm seeing a spike in CPU when cells go off screen. Profiling suggests it's Auto Layout recalculating constraints when the cell's view frame is set to CGRectZero. I've mitigated the CPU spike (and corresponding scroll lag) by overriding setFrame and not calling super if it's passed CGRectZero. This begs the question: What is the use of setting the cell to CGRectZero in the first place? Is that designed to limit off-screen rendering?
Hey Caylan,
Cells are not taken out of their parent view, so CGRectZero is essentially a safeguard to keep them out of the viewport. They are hidden though, so perhaps thats good enough.
Gotcha. Well, for what it's worth, IGFlowView setting the cell's frame to CGRectZero has generated about 6 hours of debugging and dead-end performance optimizations on my end, so hopefully this forum post is not in vain. :)