You can track the last touch date and compare with the current touch date. If the difference is small enough (0.7 s), you can consider it a double tap.
Inject this into a subclass UITabVarControllerusing the delegate method shouldSelectViewController.
Here is the working code that I use.
#import "TabBarController.h"
#import "TargetVC.h"
@interface TabBarController ()
@property(nonatomic,retain)NSDate *lastTouchDate;
@end
@implementation TabBarController
- (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;
}
source
share