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

Dismiss Menu on outside click #23

Closed
girubhai opened this issue Oct 29, 2015 · 2 comments
Closed

Dismiss Menu on outside click #23

girubhai opened this issue Oct 29, 2015 · 2 comments

Comments

@girubhai
Copy link

Is there any method to dismiss menu on outside click,I found whole cell clickable therefore on click empty space it handle menu action.

Anyway,thanks for great menu.

@paresh-navadiya
Copy link

One solution is to add footerview in uitableview which is clickable

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    CGFloat viewHeight = self.view.frame.size.height;
    CGFloat menuHeight = self.menuTitles.count*65.0;
    CGFloat height = 0.0f;
    if (menuHeight<viewHeight) //check if there is need to add footerview
       height = viewHeight-menuHeight;

    return height;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

    CGFloat viewHeight = self.view.frame.size.height;
    CGFloat menuHeight = self.menuTitles.count*65.0;
    CGFloat height = 0.0f;
    if (menuHeight<viewHeight)  //check if there is need to add footerview
       height = viewHeight-menuHeight;

    UIButton *btnFooter = [[UIButton alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,height)];
    [btnFooter addTarget:self action:@selector(dismissMenuWhenClickedOnEmptySpace:) forControlEvents:UIControlEventTouchUpInside];
    //btnFooter.layer.borderColor = [UIColor whiteColor].CGColor;
    //btnFooter.layer.borderWidth = 2.0f;

     return btnFooter;
}

Add button's click event

-(void)dismissMenuWhenClickedOnEmptySpace:(id)sender
{
    NSIndexPath *cancelIndPath = [NSIndexPath indexPathForRow:0 inSection:0];
    NSLog(@"cancelIndPath : %@",cancelIndPath);
    [_contextMenuTableView dismisWithIndexPath:cancelIndPath];
}

@KaterynaZaikina
Copy link

@girubhai, yes, whole cell is clickable and handles menu action. If you want to dismiss menu on click, you can follow @paresh-navadiya advice and use footer view and gestureRecognizer instead of button.
Moreover, you can use YALTableView method 'showInView:withEdgeInsets:animated:" to set left and bottom insets, add gestureRecogniser to superview to dismiss menu.

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

4 participants