GithubHelp home page GithubHelp logo

Comments (12)

mwyman avatar mwyman commented on June 12, 2024

This as a problem with the gesture recognizers detecting taps gobbling presses on cell views.

I've gotten around this problem by modifying the GMGridView's -gestureRecognizer:shouldRecieveTouch: to return false for either the tap or long-press gestures when the touched view is a subclass of UIControl or the descendent of one.

from gmgridview.

flexaddicted avatar flexaddicted commented on June 12, 2024

@mwyman Thank you very much for your reply. Do I have to use the gesture recognizer's view property and check if it's an UIControl class? Could you provide a simple snippet to reach the goal? Thank you.

from gmgridview.

flexaddicted avatar flexaddicted commented on June 12, 2024

I figured out a way to do it. For the sake of completeness I post the code I'm using. Maybe someone could be interested in.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if(gestureRecognizer == _tapGesture) {

        UIView* touchedView = [touch view];
        if([touchedView isKindOfClass:[UIButton class]]) {

            return NO;
        }
    }

    return YES;
}

from gmgridview.

mwyman avatar mwyman commented on June 12, 2024

That should work in most cases. However, you should also test against the _sortingLongPressGesture, and you may want to check whether the touched view is a descendent of a UIButton (actually, I'd generalize to UIControl).

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ( gestureRecognizer == _tapGesture || gestureRecognizer == _sortingLongPressGesture ) {
        if ( [touch.view isDescendantOfView:self] ) {
            // Test if the touched view is a subview of a control
            for ( UIView *view = touch.view ; view != self ; view = view.superview )
                if ( [view isKindOfClass:[UIControl class]] )
                    return NO;
        }
    }

    return YES;
}

from gmgridview.

DioNNiS avatar DioNNiS commented on June 12, 2024

mwyman, nice solution!

from gmgridview.

 avatar commented on June 12, 2024

Hey flexaddicted, I've tried adding a UIButton as a subview of my custom view but I can't get it to appear. Any idea what's missing?

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
    view.backgroundColor = [UIColor greenColor];
    view.layer.masksToBounds = NO;
    view.layer.cornerRadius = 15;

    UIButton *plainButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [plainButton setImage:[UIImage imageNamed:@"Itsy1.jpg"] forState:UIControlStateNormal];
    [plainButton setFrame:CGRectMake(0, 0, 50, 50)];
    [plainButton setTitle:@"Button" forState:UIControlStateNormal];
    [view addSubview:plainButton];
    [view bringSubviewToFront:plainButton];

    cell.contentView = view;

from gmgridview.

mrevoir avatar mrevoir commented on June 12, 2024

flexaddicted, how did you go about knowing which position in the grid view was being clicked?

from gmgridview.

Ricardo1980 avatar Ricardo1980 commented on June 12, 2024

Do I have to modify your source code to add a button? If I use a XIB, do I also have to modify the grid source code? Thanks.

from gmgridview.

flexaddicted avatar flexaddicted commented on June 12, 2024

@DigiCub Seems ok to me. I don't know what the problem could be.

@mrevoir Could you explain what do you mean?

@Ricardo1980 You need to create a view with its button and add it as the contentView of the cell. Yes, you have to modify the code also with a xib.

from gmgridview.

mrevoir avatar mrevoir commented on June 12, 2024

@flexaddicted In thinking about how to better describe my question it struck me to look at how cell deletion currently works so I'll do that as well, but I am wondering how to determine which cell in the grid contained the button that was clicked. I can see that the button is receiving the event because my selector is invoked, but I don't know which of the buttons in the grid was clicked.

from gmgridview.

mwyman avatar mwyman commented on June 12, 2024

One method would be to use setTag: on your buttons when you get the cell in GMGridView:cellForItemAtIndex:, setting it to the index of the cell. Note that you will need to do this every time you recycle a cell, not just when you create the buttons.

from gmgridview.

exalted avatar exalted commented on June 12, 2024

Thanks! I would love to see this merged on the master though.

from gmgridview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.