GMGridView icon indicating copy to clipboard operation
GMGridView copied to clipboard

How can I move (change the position ) + delete the the cells using long press

Open nfs3250 opened this issue 12 years ago • 12 comments

First of all Thanks for very useful & awesome library. My questions are

  1. How can I move the cells & also delete the cells using Long Press ? I want to give both moving + deleting functionality same as iOS spring board in my app.

  2. I have added one more UIView(gridContentView) in my UIViewController. Now I want to show GMGridView in gridContentView. I tried setting gmGridView.mainSuperView = self.gridContentView; but still my grids scroll above that view. How can I change mainSuperView ?

Any kind of help is appreciated. Thanks in advance

nfs3250 avatar Jun 19 '12 10:06 nfs3250

+1

  1. I have added one more UIView(gridContentView) in my UIViewController. Now I want to show GMGridView in gridContentView. I tried setting gmGridView.mainSuperView = self.gridContentView; but still my grids scroll above that view. How can I change mainSuperView ?

trawor avatar Jun 21 '12 10:06 trawor

Why do you need a containerView for the Gridview? You can just set the frame of the GridView if you want it to be smaller. And be sure to set clipsToBounds = YES to avoid cells being displayed out of the gridviews bounds.

Maverick1st avatar Jun 25 '12 14:06 Maverick1st

Regarding your 1st Point. Have you tried to set your gridview to editing mode in the handle method of the longPressGestureRecognizer? Should work if you do the same as in the Example. Like calling

- (void)editingSwitchChanged:(UISwitch *)control
{
    self.gridView.editing = control.on;
    control.on = self.gridView.isEditing;
    [self.gridView layoutSubviewsWithAnimation:GMGridViewItemAnimationFade];
}

Maverick1st avatar Jun 25 '12 15:06 Maverick1st

@Maverick1st thx for reply, I had try clipsToBounds = YES in the example code it should be _gmGridView1.clipsToBounds=YES; but it does work as I wish, it still looks like this: screenshot

trawor avatar Jun 26 '12 03:06 trawor

@trawor , I tried the above solution of setting required frame & then using clipToBounds = YES & it works perfectly. Here is my code if you need it

-(void)setUpGridView { NSInteger spacing = 8; GMGridView *tempgmGridView = [[GMGridView alloc] initWithFrame:CGRectMake(0.0, 60.0, 320.0, 352.0)]; tempgmGridView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; tempgmGridView.backgroundColor = [UIColor clearColor]; [self.view addSubview:tempgmGridView]; gmGridView = tempgmGridView; gmGridView.clipsToBounds = YES; gmGridView.style = GMGridViewStyleSwap; gmGridView.itemSpacing = spacing; gmGridView.minEdgeInsets = UIEdgeInsetsMake(spacing, spacing, spacing, spacing); gmGridView.centerGrid = YES; gmGridView.actionDelegate = self; gmGridView.sortingDelegate = self; gmGridView.transformDelegate = self; gmGridView.dataSource = self; }

Now my GridView scrolls within the frame. Try to set FRAME of GMGridView also along with clipToBounds = YES

nfs3250 avatar Jun 26 '12 04:06 nfs3250

@Maverick1st Thanks for reply. I tried to set gridview to editing mode in the handle method of the longPressGestureRecognizer as follows

  • (void)longPressGestureUpdated:(UILongPressGestureRecognizer *)longPressGesture {

    self.editing = YES; self.enableEditOnLongPress = YES; // Remaining code in this method

}

But it works for first time & afterwards its not working because

// Editing Mode @property (nonatomic, getter=isEditing) BOOL editing; // Default is NO - When set to YES, all gestures are disabled and delete buttons shows up on cells

Can you tell me what should I do ?

nfs3250 avatar Jun 26 '12 04:06 nfs3250

What do you do, when you want to leave editing mode? Of course you have to reset all variables to the state they were before entering editing mode. It seems to me, that you have missed something.

Maverick1st avatar Jun 26 '12 13:06 Maverick1st

I am not getting what I am doing wrong. Where should I reset & which variables ? Sorry. Can you tell me what I need to do? Thanks

nfs3250 avatar Jun 26 '12 15:06 nfs3250

I cannot help you, when you are not answering my questions ;). What do you do, when you want to leave editing mode? Do push a button, or what? When you have entered Editing mode Gestures are disabled, so that you cannot accidentally trigger the tap or the pan action, i guess. So since you are in editing mode and the longPressGesture is disabled you have to return to non-editing state via a buttonpress. Of course you have to create the button by yourself. Just look at the examples. It should be much clearer then.

And of course it is always better not to just use the code some one gives you, but to understand it. I know this is a lot of work, but it will massively improve your programming skills :).

Maverick1st avatar Jun 27 '12 07:06 Maverick1st

I took a crack at this one, as well as merging #47 in my fork of GMGridView. I'll submit a pull request once I have a chance to test more. Feel free to test it out and let me know if you have any feedback.

https://github.com/shacked/GMGridView

chadpod avatar Aug 08 '12 02:08 chadpod

How can i enable long press gesture enable on edit mode ?

asankamadushan avatar Feb 22 '13 07:02 asankamadushan

This is a solution for above problem http://roshankularathna.blogspot.com/2013/03/gmgridview-long-press-delete-and-moving.html

chathurka avatar Mar 26 '13 08:03 chathurka