0

I am creating a barbuttonitem with the following code and i am adding a gesture recognizer to the navigation bar. So i need to know when the user tapped on the left or right of the barbuttonitem by 25 pixels. Is this possible using the gesture recognizer? Any help appreciated...

UIButton *searchButton = [self createSearchButton];

 UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGestureForTopLeftNotificationBarButtonItem:)];
           [self.navigationController.navigationBar addGestureRecognizer:gr];

- (UIButton *) createSearchButton {
    UIButton *searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [searchButton setImage:[UIImage sdk_imageName:@"Search_header_black"]
                 forState:UIControlStateNormal];
    
    [searchButton addTarget:self action:@selector(searchBarButtonClick) forControlEvents:UIControlEventTouchUpInside];
    searchButton.size = CGSizeMake(32, 30);
    searchButton.imageEdgeInsets = UIEdgeInsetsMake( 0, 8, 0, 0);
    return searchButton;


 
}
stefanosn
  • 3,264
  • 10
  • 53
  • 79
  • What's the method `handleGestureForTopLeftNotificationBarButtonItem:`? From the tap gesture, you could get the location of the tap inside the view, and then guess if it fits your needs? – Larme Jun 13 '22 at 17:37
  • Does this answer your question? [How to get UITouch location from UIGestureRecognizer](https://stackoverflow.com/questions/16618109/how-to-get-uitouch-location-from-uigesturerecognizer) – Larme Jun 13 '22 at 17:38

0 Answers0