można śledzić ostatni dzień dotykowym i porównania z aktualną datą dotykowym. Jeśli różnica jest wystarczająco mała (0,7 s), możesz uznać to za podwójne dotknięcie.
Zaimplementuj to w podklasie UITabVarController
, używając metody delegowania shouldSelectViewController
.
Oto działający kod, którego używam.
#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;
}
jest tym odradzanym? – bluezald