如何在UITabBarItem上实现双击,以便它可以向上滚动UITableView,就像Twitter应用程序一样?或者任何参考,都可以
谢谢
您可以跟踪上次触摸日期并与当前触摸日期进行比较。如果差异足够小(0.7 秒),您可以将其视为双击。
UITabVarController在使用委托方法的子类中实现此功能shouldSelectViewController。
这是我正在使用的工作代码。
#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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
870 次 |
| 最近记录: |