@@ -110,7 +110,7 @@ - (void)setupCollectionView {
110110
111111- (id )init {
112112 self = [super init ];
113- if (self) {
113+ if (self){
114114 [self setDefaults ];
115115 [self addObserver: self forKeyPath: kLXCollectionViewKeyPath options: NSKeyValueObservingOptionNew context: nil ];
116116 }
@@ -119,7 +119,7 @@ - (id)init {
119119
120120- (id )initWithCoder : (NSCoder *)aDecoder {
121121 self = [super initWithCoder: aDecoder];
122- if (self) {
122+ if (self){
123123 [self setDefaults ];
124124 [self addObserver: self forKeyPath: kLXCollectionViewKeyPath options: NSKeyValueObservingOptionNew context: nil ];
125125 }
@@ -199,11 +199,15 @@ - (void)moveCurrentItemToIndexPath:(NSIndexPath *)newIndexPath {
199199}
200200
201201- (void )dropCurrentItemOnIndexPath : (NSIndexPath *)newIndexPath {
202- if ((newIndexPath == nil ) || [newIndexPath isEqual: self .selectedItemIndexPath] || [newIndexPath isEqual: self .catchItemIndexPath] ) {
202+ if ((newIndexPath == nil ) || [newIndexPath isEqual: self .selectedItemIndexPath]) {
203203 [self resetCatchItemIfNeeded ];
204204 return ;
205205 }
206206
207+ if ([newIndexPath isEqual: self .catchItemIndexPath]) {
208+ return ;
209+ }
210+
207211 if (![self .dataSource respondsToSelector: @selector (collectionView:canDropItemAtIndexPath:toIndexPath: )]) {
208212 [self moveCurrentItemToIndexPath: newIndexPath];
209213 return ;
@@ -223,12 +227,22 @@ - (void)invalidateLayoutIfNecessary {
223227
224228 UICollectionViewLayoutAttributes *theLayoutAttributesOfSelectedItem = [self layoutAttributesForItemAtIndexPath: newIndePath];
225229 CGRect theFrame = theLayoutAttributesOfSelectedItem.frame ;
226- CGRect intersectionFrame = CGRectIntersection (self.currentView .frame , theFrame);
230+ CGRect theLeftFrame, theRightFrame;
231+ // CGRectDivide(theFrame, &theLeftFrame, &theRightFrame, CGRectGetWidth(theFrame) / 2.0f, CGRectMinXEdge);
232+ CGRectDivide (theFrame, &theLeftFrame, &theRightFrame, CGRectGetHeight (theFrame) / 2 .0f , CGRectMinYEdge);
227233
228- if (intersectionFrame.size .height > theFrame.size .height /2 || intersectionFrame.size .width > theFrame.size .width /2 ) {
229- [self dropCurrentItemOnIndexPath: newIndePath];
230- } else {
231- [self moveCurrentItemToIndexPath: newIndePath];
234+ if (CGRectContainsPoint (theLeftFrame, theCurrentViewCenter)) {
235+ if (self.selectedItemIndexPath .item > newIndePath.item ) {
236+ [self moveCurrentItemToIndexPath: newIndePath];
237+ } else {
238+ [self dropCurrentItemOnIndexPath: newIndePath];
239+ }
240+ } else if (CGRectContainsPoint (theRightFrame, theCurrentViewCenter)) {
241+ if (self.selectedItemIndexPath .item < newIndePath.item ) {
242+ [self moveCurrentItemToIndexPath: newIndePath];
243+ } else {
244+ [self dropCurrentItemOnIndexPath: newIndePath];
245+ }
232246 }
233247}
234248
0 commit comments