Skip to content
This repository was archived by the owner on Oct 31, 2019. It is now read-only.

Fixes #21 #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions DraggableCollectionView/Helpers/LSCollectionViewHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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 <UICollectionViewLayout_Warpable>)self.collectionView.collectionViewLayout layoutHelper];
Expand Down Expand Up @@ -259,8 +286,8 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)sender
}
// Tell the data source to move the item
[(id<UICollectionViewDataSource_Draggable>)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:^{
Expand Down Expand Up @@ -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;
Expand Down