• 35648

    文章

  • 23

    评论

  • 20

    友链

  • 最近新加了很多技术文章,大家多来逛逛吧~~~~
  • 喜欢这个网站的朋友可以加一下QQ群,我们一起交流技术。

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

欢迎来到阿八个人博客网站。本 阿八个人博客 网站提供最新的站长新闻,各种互联网资讯。 喜欢本站的朋友可以收藏本站,或者加QQ:我们大家一起来交流技术! URL链接:https://www.abboke.com/jsh/2019/0813/105355.html

- (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 < self.conversations.count; i++) {
                    WFCCConversationInfo *lastModel = self.conversations[i];
                    if (lastModel.unreadCount.unread>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];
}

 

相关文章

暂住......别动,不想说点什么吗?
  • 全部评论(0
    还没有评论,快来抢沙发吧!