Нажмите «Жест» на кнопке «UITabbar»

Я создал проект с контроллером вкладок. На моей вкладке есть 5 кнопок, теперь я хочу сделать распознаватель жестов двойного нажатия на моей первой вкладке.

Мне удалось сделать жест на панели вкладок, но когда я дважды нажимаю любую кнопку на панели вкладок, вызывается метод. Как сделать это только для одной кнопки tabbarbutton?

 -(void)createTab{

     Array = [[NSMutableArray alloc] initWithCapacity:5];

    myhomeVC = [[MyHomeViewController alloc] initWithNibName:@"MyHomeViewController" bundle:nil];
 homeNavBar=[[UINavigationController alloc]initWithRootViewController:myhomeVC];

     groupVC = [[GroupSearchViewController alloc] initWithNibName:@"GroupSearchViewController" bundle:nil];
    groupNavBar=[[UINavigationController alloc]initWithRootViewController:groupVC];

    uploadVC = [[UploadFoodImageViewController alloc] initWithNibName:@"UploadFoodImageViewController" bundle:nil];
    uploadNavBar=[[UINavigationController alloc]initWithRootViewController:uploadVC];

    searchVC = [[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:nil];
    searchNavBar=[[UINavigationController alloc]initWithRootViewController:searchVC];

    nearbyVC = [[NearByViewController alloc] initWithNibName:@"NearByViewController" bundle:nil];
    nearbyNavBar=[[UINavigationController alloc]initWithRootViewController:nearbyVC];



    [Array addObject:homeNavBar];
    [Array addObject:groupNavBar];
    [Array addObject:uploadNavBar];
    [Array addObject:searchNavBar];
    [Array addObject:nearbyNavBar];

    appDelegate.tabBarController.viewControllers =Array;


     UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
    [doubleTap setNumberOfTapsRequired:2];
    [appDelegate.tabBarController.view addGestureRecognizer:doubleTap];


}




 -(void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer {
    NSLog(@"Tab tpped");
  }

person Vinay Nair    schedule 19.04.2013    source источник
comment
Вы нашли решение своей проблемы?   -  person Raj    schedule 21.08.2014
comment
Вам удалось это реализовать?   -  person Chris Edwards    schedule 25.03.2015


Ответы (1)


У меня есть трюк, чтобы сделать это. Вы тоже попробуйте, может пригодится. Я все еще работаю над этим.

Перейти к shouldSelectViewController методу делегирования. Этот метод срабатывает каждый раз при касании элемента. Все эти случаи оператора switch являются щелчками разных вкладок приложения.

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    DBGS;
    switch (viewController.tabBarItem.tag)
    {
        case 0:
        {
            _tapCounter++; // Here I am increasing a NSInteger count to check how many times it increaed
            if(_tapCounter == 2) // it is tapped twice, so select this case
            {
                DBG(@"Double Tap done");
                [[(AppDelegate *)[[UIApplication sharedApplication] delegate] fvc] getFeeds]; // write your code that you want on double tap
                _tapCounter = 0; // making it zero again
            }
            [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(tapZero) userInfo:self repeats:NO]; // this timer waits for 1 sec (bacause 1 sec is long and double tap should be in few miliseconds), then again makes _tapCounter to zero.
        }
            break;
        case 1:
        {

        }
            break;
        case 2:
        {

        }
            break;
        case 3:
        {

        }
        case 4:
        {

        }
            break;
        default:
            break;
    }
    return YES;
}

- (void)tapZero
{
    _tapCounter = 0; // _tapCounter is zero here
}
person Vaibhav Saran    schedule 18.02.2016