Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tapping on buttons with the badges sometime do not work #17

Open
maxykato opened this issue Dec 20, 2015 · 3 comments
Open

Tapping on buttons with the badges sometime do not work #17

maxykato opened this issue Dec 20, 2015 · 3 comments

Comments

@maxykato
Copy link

I implemented this library in my Swift project, and it works great. I really appreciate it.

The only problem I have is that tapping on the buttons with the badges sometime fails. I assume that it might be because badges do not accept touch gestures and the size of touchable area on the buttons becomes smaller.

Is possible to fix it?
Or is there any workaround?

@maxykato
Copy link
Author

maxykato commented Feb 8, 2016

Looking forward to any reply...

@halset
Copy link

halset commented Jan 17, 2018

I have the same problem. Did you find a solution, @maxykato ?

@Guruniverse
Copy link

The badge is implemented as a UILabel on top of the UIButton preventing it to receive the touch events. I managed to address the issue by adding a gesture recognizer on the badge itself.

    UIImage *image = [UIImage imageNamed:@"navbarIconShareSelected"];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0,0,image.size.width, image.size.height);
    [button addTarget:self action:@selector(shareButtonPressed) forControlEvents:UIControlEventTouchDown];
    [button setBackgroundImage:image forState:UIControlStateNormal];
    
    UIBarButtonItem *navRightButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = navRightButton;

    // The badge on the uibarbutton is a UILabel that prevent taps to trigger the shareButtonPressed event. Add a gesture recognizer to capture tap events
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self
                                            action:@selector(shareButtonPressed)];
    [navRightButton.badge addGestureRecognizer:tapGesture];
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants