-
Notifications
You must be signed in to change notification settings - Fork 325
Description
There is a behaviour on the current iOS version (11.4, not sure when this behaviour started) where if a collection view's layout is set after initialization - instead of it being passed inside init(frame:collectionViewLayout:) - the collectionView property will be set twice.
That is, if you do this
let collectionView = UICollectionView(
frame: .zero,
collectionViewLayout: UICollectionViewFlowLayout()
)
collectionView.collectionViewLayout = LXReorderableCollectionViewFlowLayout()instead of this
let collectionView = UICollectionView(
frame: .zero,
collectionViewLayout: LXReorderableCollectionViewFlowLayout()
)KVO will cause setupCollectionView to be called twice. Consequently the stored panGestureRecognizer is replaced with a new one, but the old one is still listening to gestures on the collection view.
This breaks scrolling, because scrolling over the collection view when self.selectedItemIndexPath is nil should not trigger handlePanGesture, but it does because this
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if ([self.panGestureRecognizer isEqual:gestureRecognizer]) {
return (self.selectedItemIndexPath != nil);
}
return YES;
}returns true for the replaced (but still listening) pan gesture recognizer.