Во-первых, вот сообщение об ошибке, которое я получаю:
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, так как текущий метод уже чувствует себя как-то хакерским.