简体   繁体   中英

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.

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM