Skip to content

Commit c33a2ec

Browse files
author
Jim Dovey
committed
Handle the case where the dragged-to cell index isn't in the grid by snapping the drag target back to the last place in the grid.
1 parent dbf2084 commit c33a2ec

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Examples/SpringBoard/Classes/SpringBoardViewController.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ - (void) moveActionGestureRecognizerStateChanged: (UIGestureRecognizer *) recogn
199199
{
200200
CGPoint p = [recognizer locationInView: _gridView];
201201
NSUInteger index = [_gridView indexForItemAtPoint: p];
202+
if ( index == NSNotFound )
203+
{
204+
// index is the last available location
205+
index = [_icons count] - 1;
206+
}
202207

203208
// update the data store
204209
id obj = [[_icons objectAtIndex: _dragOriginIndex] retain];
@@ -282,6 +287,14 @@ - (void) moveActionGestureRecognizerStateChanged: (UIGestureRecognizer *) recogn
282287

283288
// update empty cell to follow, if necessary
284289
NSUInteger index = [_gridView indexForItemAtPoint: [recognizer locationInView: _gridView]];
290+
291+
// don't do anything if it's over an unused grid cell
292+
if ( index == NSNotFound )
293+
{
294+
// snap back to the last possible index
295+
index = [_icons count] - 1;
296+
}
297+
285298
if ( index != _emptyCellIndex )
286299
{
287300
NSLog( @"Moving empty cell from %u to %u", _emptyCellIndex, index );

0 commit comments

Comments
 (0)