首先,这是我收到的错误消息:
2018-10-08 01:10:04.886509-0600 Nebula Messenger[1542:262927] [CollectionView] An attempt to prepare a layout while a prepareLayout call was already in progress (i.e. reentrant call) has been ignored. Please file a bug. UICollectionView instance is (<UICollectionView: 0x10703e600; frame = (0 92; 375 491); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x281a741e0>; layer = <CALayer: 0x281431da0>; contentOffset: {0, -8}; contentSize: {375, 0}; adjustedContentInset: {8, 0, 8, 0}> collection view layout: <UICollectionViewFlowLayout: 0x10605fe10>)
2018-10-08 01:10:04.891365-0600 Nebula Messenger[1542:262927] [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:0x283726670 UIView:0x106065480.width == 200 (active)>",
"<NSLayoutConstraint:0x283726760 UILabel:0x106065190.left == UIView:0x106065480.left + 8 (active)>",
"<NSLayoutConstraint:0x2837267b0 UILabel:0x106065190.right == UIView:0x106065480.right - 8 (active)>",
"<NSLayoutConstraint:0x283726850 UILabel:0x106065190.width == 200 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x283726850 UILabel:0x106065190.width == 200 (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.
2018-10-08 01:10:04.896386-0600 Nebula Messenger[1542:262927] [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:0x28372bac0 UIView:0x1061705c0.width == 200 (active)>",
"<NSLayoutConstraint:0x28372bbb0 UILabel:0x1061702d0.left == UIView:0x1061705c0.left + 8 (active)>",
"<NSLayoutConstraint:0x28372bc00 UILabel:0x1061702d0.right == UIView:0x1061705c0.right - 8 (active)>",
"<NSLayoutConstraint:0x28372bca0 UILabel:0x1061702d0.width == 200 (active)>"
)
这是我用来滚动的:
func scrollToBottom() {
DispatchQueue.main.async {
self.messagesCollection.layoutIfNeeded()
self.messagesCollection?.scrollToItem(at: IndexPath(item:
self.msgList.count-1, section: 0), at:
UICollectionView.ScrollPosition.bottom, animated: true)
}
}
当视图加载时,我称之为:
override func viewDidLayoutSubviews(){
super.viewDidLayoutSubviews()
self.messagesCollection.layoutIfNeeded()
self.scrollToBottom()
}
我的第一个问题是它加载时不会向右滚动,我必须先手动滚动它,然后它会向上滚动到底部。
也就是说,除非CollectionView中有很多单元格,在这种情况下,它将继续尝试向上滚动我,直到我与它抗争到可以让它向相反方向滚动为止。
第二个问题(这似乎是主要问题)是错误消息。我得到了很多,基本上它只是告诉我,为了滚动,必须打破限制,但这对我没有任何意义。滚动如何打破约束?
这个
scrollToBottom
函数在放置时不起作用
viewDidLoad
或
viewDidAppear
.
我并不反对使用不同的方法来滚动CollectionView,因为当前的方法已经感觉有点老套了。