博客> 双击tabbar回顶部
双击tabbar回顶部
2019-10-23 07:13 评论:0 阅读:787 nice_future
tabbar

话不多说,直接上代码

NSString *const kDoubleClickTabItemNotification = @"kDoubleClickTabItemNotification"; DDRootTabController.m

  • (BOOL)checkIsDoubleClick:(UIViewController )viewController { static UIViewController lastViewController = nil; static NSTimeInterval lastClickTime = 0;

    if (lastViewController != viewController) { lastViewController = viewController; lastClickTime = [NSDate timeIntervalSinceReferenceDate]; return NO; }

    NSTimeInterval clickTime = [NSDate timeIntervalSinceReferenceDate]; if (clickTime - lastClickTime > 0.5 ) { lastClickTime = clickTime; return NO; }

    lastClickTime = clickTime; return YES; }

  • (BOOL)tabBarController:(UITabBarController )tabBarController shouldSelectViewController:(UIViewController )viewController { if ([self checkIsDoubleClick:viewController]) { // TODO ... NSLog(@"isDoubleClick"); [[NSNotificationCenter defaultCenter] postNotificationName:kDoubleClickTabItemNotification object:nil]; return YES; } return NO; }

DDHomeController.m @property (nonatomic, strong) UIViewController displayViewController; extern NSString const kDoubleClickTabItemNotification; [DD_NOTIFICATION_CENTER addObserver:self selector:@selector(doubleClickedScrollToTop:) name:kDoubleClickTabItemNotification object:nil];

  • (void)doubleClickedScrollToTop:(NSNotification )noti { BOOL isDriverHome = NO; if ([[NSUserDefaults standardUserDefaults] objectForKey:@"role_type"]) { if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"role_type"] intValue] == kUserRoleTypeDriver) { isDriverHome = YES; } } if ([self.displayViewController respondsToSelector:@selector(scrollToTop)]) { if (isDriverHome) { [(DDDriverHomeViewController )self.displayViewController scrollToTop]; } else { [(DDDriverHomeViewController *)self.displayViewController scrollToTop];

    }

    } }

DDPassengerHomeViewController.m

  • (void)scrollToTop { [self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES]; // [self.tableView setContentOffset:CGPointZero animated:YES]; }
收藏
0
sina weixin mail 回到顶部