Double click on UITabBarItem to scroll up and reload as a Twitter app

How do you double-click on UITabBarItem so that it scrolls through the UITableView, for example, what does the Twitter application do? Or any link for this will do

thank

+5
source share
3 answers

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

//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;
}
+1
source

On the tab, you can add a highlight gesture:

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

You can see the UITabBarItem (QMUI) code in QMUI iOS , it supports using the block if the user touches twice UITabBarItem, and you can find an example code for it here .

tabBarItem.qmui_doubleTapBlock = ^(UITabBarItem *tabBarItem, NSInteger index) {
    // do something you want...
};
0
source

All Articles