Double-tap the UINavigationController navigationBar?

I have an application with a long list of data in the View table, and I would like to double-tap the navigation bar to scroll through the UITableView at the top of the list (where the search is being performed).

How to implement this?

Thank you for your help.

+3
source share
2 answers

The standard gesture for scrolling through the View table at the top is a single click on the status bar. It is enabled by default, see UIScrollView Help

If you really need a navigation bar, and you focus on 3.2 and higher, I would recommend connecting the UITapGestureRecognizer to the navigationBar.

- (void)viewDidLoad {
    UITapGestureRecognizer* tapRecon = [[UITapGestureRecognizer alloc]
              initWithTarget:self action:@selector(navigationBarDoubleTap:)];
    tapRecon.numberOfTapsRequired = 2;
    [navController.navigationBar addGestureRecognizer:tapRecon];
    [tapRecon release];
}

- (void)navigationBarDoubleTap:(UIGestureRecognizer*)recognizer {
    [tableView setContentOffset:CGPointMake(0,0) animated:YES];
}

3.0 , .

+16

, , .

:

0 leftbutton, 1 , 2,

:

[navController.navigationBar addGestureRecognizer:tapRecon];

:

[[self.navigationController.navigationBar.subviews objectAtIndex:1] setUserInteractionEnabled:YES];
[[self.navigationController.navigationBar.subviews objectAtIndex:1] addGestureRecognizer:tapRecon];
+9

Source: https://habr.com/ru/post/1754183/


All Articles