diff --git a/DraggableCollectionView/Helpers/LSCollectionViewHelper.m b/DraggableCollectionView/Helpers/LSCollectionViewHelper.m index 9075b07..52f265a 100644 --- a/DraggableCollectionView/Helpers/LSCollectionViewHelper.m +++ b/DraggableCollectionView/Helpers/LSCollectionViewHelper.m @@ -37,8 +37,15 @@ @interface LSCollectionViewHelper () _ScrollingDirection scrollingDirection; BOOL canWarp; BOOL canScroll; + + id __weak _observerForUIKeyboardWillShowNotification; + id __weak _observerForUIKeyboardDidHideNotification; + + } @property (readonly, nonatomic) LSCollectionViewLayoutHelper *layoutHelper; +@property (nonatomic) BOOL wasEnabledBeforKeyBoardShow; + @end @implementation LSCollectionViewHelper @@ -63,7 +70,7 @@ - (id)initWithCollectionView:(UICollectionView *)collectionView _panPressGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)]; _panPressGestureRecognizer.delegate = self; - + [_collectionView addGestureRecognizer:_panPressGestureRecognizer]; for (UIGestureRecognizer *gestureRecognizer in _collectionView.gestureRecognizers) { @@ -74,10 +81,30 @@ - (id)initWithCollectionView:(UICollectionView *)collectionView } [self layoutChanged]; + + LSCollectionViewHelper __weak *weakSelf=self; + _observerForUIKeyboardWillShowNotification=[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillShowNotification + object:nil + queue:nil + usingBlock:^(NSNotification *note) { + weakSelf.wasEnabledBeforKeyBoardShow=weakSelf.enabled; + weakSelf.enabled=NO; + }]; + + _observerForUIKeyboardDidHideNotification=[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardDidHideNotification + object:nil + queue:nil + usingBlock:^(NSNotification *note) { + weakSelf.enabled=weakSelf.wasEnabledBeforKeyBoardShow; + }]; + + } return self; } + + - (LSCollectionViewLayoutHelper *)layoutHelper { return [(id )self.collectionView.collectionViewLayout layoutHelper]; @@ -259,8 +286,8 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)sender } // Tell the data source to move the item [(id)self.collectionView.dataSource collectionView:self.collectionView - moveItemAtIndexPath:self.layoutHelper.fromIndexPath - toIndexPath:self.layoutHelper.toIndexPath]; + moveItemAtIndexPath:self.layoutHelper.fromIndexPath + toIndexPath:self.layoutHelper.toIndexPath]; // Move the item [self.collectionView performBatchUpdates:^{ @@ -304,8 +331,8 @@ - (void)warpToIndexPath:(NSIndexPath *)indexPath collectionView:self.collectionView canMoveItemAtIndexPath:self.layoutHelper.fromIndexPath toIndexPath:indexPath] == NO) { - return; - } + return; + } [self.collectionView performBatchUpdates:^{ self.layoutHelper.hideIndexPath = indexPath; self.layoutHelper.toIndexPath = indexPath;