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;
}
¿está desaconsejado? – bluezald