2011-10-10 11 views
5

जैसे स्क्रॉल अप और रीलोड करने के लिए UITabBarItem पर डबल टैप करें, आप UITabBarItem पर डबल टैप कैसे कार्यान्वित करते हैं ताकि यह UITableView को स्क्रॉल करेगा, जैसे कि ट्विटर ऐप क्या करता है? या इस के लिए किसी भी संदर्भ,ट्विटर ऐप

धन्यवाद

+0

क्या यह एक निराश है? – bluezald

उत्तर

1

आप अंतिम स्पर्श तारीख का ट्रैक रखने और वर्तमान स्पर्श तारीख करने के लिए तुलना कर सकते हैं करेंगे। यदि अंतर पर्याप्त छोटा है (0.7sec) तो आप इसे एक डबल टैप मान सकते हैं।

एक प्रतिनिधि विधि shouldSelectViewController का उपयोग करके UITabVarController के उप-वर्ग में इसे कार्यान्वित करें।

यहां एक कामकाजी कोड है जिसका मैं उपयोग कर रहा हूं।

#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

आप tabbar पर एक नल इशारा जोड़ सकते हैं:

-(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

आप QMUI iOS में UITabBarItem (QMUI) का कोड देख सकते हैं, यह एक ब्लॉक करता है, तो उपयोगकर्ता डबल टैप UITabBarItem का उपयोग करने का समर्थन करता है, और आप कर सकते हैं here के लिए नमूना कोड खोजें।

tabBarItem.qmui_doubleTapBlock = ^(UITabBarItem *tabBarItem, NSInteger index) { 
    // do something you want... 
}; 
संबंधित मुद्दे