2011-10-10 15 views

Respuesta

1

Puede llevar un registro de la última fecha de contacto y comparar a la fecha toque actual. Si la diferencia es lo suficientemente pequeña (0,7 s), puede considerar que es un doble toque.

Implemente esto en una subclase de UITabVarController utilizando un método delegado shouldSelectViewController.

Aquí hay un código de trabajo que estoy usando.

#import "TabBarController.h" 
#import "TargetVC.h" 

@interface TabBarController() 

@property(nonatomic,retain)NSDate *lastTouchDate; 

@end 

@implementation TabBarController 

//Remeber to setup UINavigationController of each of the tabs so that its restorationIdentifier is not nil 
//You can setup the restoration identifier in the IB in the identity inspector for you UIViewController or your UINavigationController 
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{ 
    NSString *tab = viewController.restorationIdentifier; 

    if([tab isEqualToString:@"TargetVC"]){ 

     if(self.lastTouchDate){ 

      UINavigationController *navigationVC = (UINavigationController*)viewController; 
      TargetVC *targetVC = (TargetVC*)navigationVC.viewControllers[0]; 

      NSTimeInterval ti = [[NSDate date] timeIntervalSinceDate:self.lastTouchDate]; 
      if(ti < 0.7f) 
       [targetVC scrollToTop]; 

     } 

     self.lastTouchDate = [NSDate date]; 
    } 

    return YES; 
} 
0

Se puede añadir un gesto de pulsar en la barra de pestañas:

-(void)addTapGestureOnTabbar 
{ 
    UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapTabbarHappend:)]; 
    tap.numberOfTapsRequired = 2; 
    tap.delaysTouchesBegan = NO; 
    tap.delaysTouchesEnded = NO; 
    [_tabBarController.tabBar addGestureRecognizer:tap]; 
} 

-(void)doubleTapTabbarHappend:(UITapGestureRecognizer *)gesture 
{ 
    CGPoint pt = [gesture locationInView:self.tabBarController.tabBar]; 
    NSInteger count = self.tabBarController.tabBar.items.count; 
    CGFloat itemWidth = [UIScreen mainScreen].bounds.size.width/(count*1.0); 
    CGFloat temp = pt.x/itemWidth; 
    int index = floor(temp); 
    if (index == kTabbarItemIndex) { 
     //here to scroll up and reload 
    } 
} 
0

se puede ver el código de UITabBarItem (QMUI) en QMUI iOS, que apoya a la utilización de un bloque si el usuario presiona dos veces la UITabBarItem, y se puede encuentre un código de muestra para él here.

tabBarItem.qmui_doubleTapBlock = ^(UITabBarItem *tabBarItem, NSInteger index) { 
    // do something you want... 
}; 
Cuestiones relacionadas