Search code examples
iosuitabbarcontrollergesture

How to add custom gesture to a tab in UITabBarController


I have a tabbarController:

UITabBarController* tabBarController = [[UITabBarController alloc] init];
UIViewController* view1 = [[UIViewController alloc] init];
UIViewController* view2 = [[UIViewController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:view1, view2, nil];

I want to add a long press gesture to view1's tab button(called tabBarItem) or just add a long press gesture to the tabbar.

How could I do?

Thanks. Any advice would be appreciated.


Solution

  • Just put your UITabbarController Methods

    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    

    and than use this for add gesture->

    UILongPressGestureRecognizer *longRecog = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressed)];
    
    [tabBarController.tabBar addGestureRecognizer:longRecog];
    

    and the selector is -

    -(void)longPressed{
        //Long pressed Occures
    
    }