iOS仿微信双击tabbar依次跳到未读消息

释放双眼,带上耳机,听听看~!
#pragma mark - delegate
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
//双击那个item
if (tabBarController.selectedIndex == 1) {
if ([self checkIsDoubleClick:viewController]) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"kDoubleClickTabItemNotification" object:nil];
}
}
return YES;
}
- (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;
}
//通知方法的实现
- (void)DoubleClickTabItemNotification{
NSLog(@"双击了 双击了 双击了 双击了");
ConversationListCell *firstCell = [self.tableView visibleCells].firstObject;
NSIndexPath *firstCellIndex = [self.tableView indexPathForCell:firstCell];
ConversationListCell *lastCell = [self.tableView visibleCells].lastObject;
NSIndexPath *lastCellIndex = [self.tableView indexPathForCell:lastCell];
if (firstCellIndex.row < self.dataArray.count-1 && lastCellIndex.row < self.dataArray.count-1) {
for (NSInteger i = firstCellIndex.row+1; i < self.dataArray.count; i++) {
EaseConversationModel *lastModel = self.dataArray[i];
if (lastModel.conversation.unreadMessagesCount>0) {
self.currentCellIndex = [NSIndexPath indexPathForRow:i inSection:0];
[self.tableView scrollToRowAtIndexPath:self.currentCellIndex atScrollPosition:UITableViewScrollPositionTop animated:YES];
break;
}
}
}else{
for (NSInteger i = 0; i < self.dataArray.count; i++) {
EaseConversationModel *lastModel = self.dataArray[i];
if (lastModel.conversation.unreadMessagesCount>0) {
self.currentCellIndex = [NSIndexPath indexPathForRow:i inSection:0];
[self.tableView scrollToRowAtIndexPath:self.currentCellIndex atScrollPosition:UITableViewScrollPositionTop animated:YES];
break;
}
}
}
}
//其它相关可能会用到的方法
//获取tableView上面所有的cell
- (NSArray *)cellsForTableView:(UITableView *)tableView
{
NSInteger sections = tableView.numberOfSections;
NSMutableArray *cells = [[NSMutableArray alloc]  init];
for (int section = 0; section < sections; section++) {
NSInteger rows =  [tableView numberOfRowsInSection:section];
for (int row = 0; row < rows; row++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
[cells addObject:[tableView cellForRowAtIndexPath:indexPath]];
}
}
return cells;
}

人已赞赏
iOS文章

iOS开发获取设备所有信息

2020-1-30 5:56:43

iOS文章

IOS开发支付宝集成支付图文教程

2020-1-30 11:57:12

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索