40°

iOS 双击TabBar移动至未读消息cell


- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    NSDate * currentDate = [NSDate new];
    ZGBaseNavigationController * nav = tabBarController.selectedViewController;
    if (([nav.viewControllers.firstObject isKindOfClass:[self class]]) && (currentDate.timeIntervalSince1970 - self.lastDate.timeIntervalSince1970) <= 0.5) {
        [self doubleSelectTabbar];
    }
    if ([nav.viewControllers.firstObject isKindOfClass:[self class]]) {
        self.lastDate = currentDate;
    }
return  true;

}

  • (void)doubleSelectTabbar{ CGRect temp = self.tableView.frame; temp.origin.y = 0; self.tableView.frame = temp; WFCUConversationTableViewCell *firstCell = [self.tableView visibleCells].firstObject; NSIndexPath *firstCellIndex = [self.tableView indexPathForCell:firstCell];

    WFCUConversationTableViewCell *lastCell = [self.tableView visibleCells].lastObject; NSIndexPath *lastCellIndex = [self.tableView indexPathForCell:lastCell];

    if (firstCellIndex.row < self.conversations.count-1 && lastCellIndex.row < self.conversations.count-1) { for (NSInteger i = firstCellIndex.row+1; i < self.conversations.count; i++) { WFCCConversationInfo *lastModel = self.conversations[i]; if (lastModel.unreadCount.unread>0) { self.currentCellIndex = [NSIndexPath indexPathForRow:i inSection:0]; [self toScrollPosition]; CGRect temp = self.tableView.frame; temp.origin.y = temp.origin.y + ( kIs_iPhoneX ? 16 : -8); self.tableView.frame = temp; break; }else{

              for (NSInteger i = 0; i &lt; self.conversations.count; i++) {
                  WFCCConversationInfo *lastModel = self.conversations[i];
                  if (lastModel.unreadCount.unread&gt;0) {
                      self.currentCellIndex = [NSIndexPath indexPathForRow:i inSection:0];
                      [self toScrollPosition];
                      break;
                  }
              }
          }
      }
    

    }else{ for (NSInteger i = 0; i < self.conversations.count; i++) { WFCCConversationInfo *lastModel = self.conversations[i]; if (lastModel.unreadCount.unread>0) { self.currentCellIndex = [NSIndexPath indexPathForRow:i inSection:0]; [self toScrollPosition]; break; } } }

    temp.origin.y = temp.origin.y + ( kIs_iPhoneX ? 16 : -8); self.tableView.frame = temp;

}

  • (void)toScrollPosition{ [self.tableView scrollToRowAtIndexPath:self.currentCellIndex atScrollPosition:UITableViewScrollPositionTop animated:YES]; }

 

本文由【west_zll】发布于开源中国,原文链接:https://my.oschina.net/wayzhu/blog/3089328

全部评论: 0

    我有话说: