How to add custom gesture to a tab in UITabBarController

1.6k views Asked by At

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.

1

There are 1 answers

0
Ghanshyam Tomar On BEST ANSWER

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

}