YBTabBarController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. //
  2. // YBTabBarController.m
  3. // WaWaJiClient
  4. //
  5. // Created by Rookie on 2017/11/15.
  6. // Copyright © 2017年 zego. All rights reserved.
  7. //
  8. #import "YBTabBarController.h"
  9. #import "YBTabBar.h"
  10. //#import "MyFollowViewController.h"
  11. #import "NearbyVC.h"
  12. #import "myVideoV.h"
  13. #import "YBHomeViewController.h"
  14. #import "YBCenterVC.h"
  15. #import "TCVideoRecordViewController.h"
  16. #import "TCVideoPublishController.h"
  17. #import "YBLiveOrVideo.h"
  18. #import "PubH5.h"
  19. #import "YBShareView.h"
  20. #import "YBUserAuthVC.h"
  21. #import "YBMsgC2CListVC.h"
  22. @interface YBTabBarController ()<YBTabBarDelegate,UITabBarControllerDelegate,V2TIMConversationListener,RTabBarDelegate>
  23. {
  24. YBHomeViewController*_homeVC;
  25. NSMutableArray *navArr;
  26. }
  27. @property (nonatomic, strong) NSDate *lastSelectedDate;
  28. @end
  29. @implementation YBTabBarController
  30. - (instancetype)initWithAlert:(BOOL)showAlert {
  31. self = [super init];
  32. if (self) {
  33. [BGSetting getBgSettingUpdate:showAlert maintain:showAlert eventBack:nil];
  34. }
  35. return self;
  36. }
  37. -(void)viewWillAppear:(BOOL)animated{
  38. [super viewWillAppear:animated];
  39. self.navigationController.navigationBarHidden = YES;
  40. }
  41. - (void)onTotalUnreadMessageCountChanged:(UInt64)totalUnreadCount {
  42. [self getUnreadCound];
  43. }
  44. -(void)getUnreadCound {
  45. __block NSInteger unRead = 0;
  46. [[YBImManager shareInstance]getAllUnredNumExceptUser:@[@"dsp_user_"] complete:^(int allUnread) {
  47. unRead = allUnread;
  48. dispatch_async(dispatch_get_main_queue(), ^{
  49. [PublicObj setTabbarBadgeValue:(int)unRead];
  50. /*
  51. YBTabBarController *tabbar = [PublicObj currentTabbar];
  52. UITabBarItem *item = [[[tabbar tabBar] items] objectAtIndex:3];
  53. //设置item角标数字
  54. if (unRead == 0) {
  55. item.badgeValue= nil;
  56. }else{
  57. item.badgeValue= [NSString stringWithFormat:@"%ld",unRead];
  58. }
  59. */
  60. });
  61. }];
  62. }
  63. - (void)viewDidLoad {
  64. [super viewDidLoad];
  65. self.delegate = self;
  66. [[V2TIMManager sharedInstance] addConversationListener:self];
  67. navArr = [NSMutableArray array];
  68. _homeVC = [[YBHomeViewController alloc]init];
  69. YBMsgC2CListVC *msgVC = [[YBMsgC2CListVC alloc]init];
  70. NearbyVC *att = [[NearbyVC alloc] init];
  71. YBCenterVC *userInfo = [[YBCenterVC alloc]init];
  72. userInfo.isTabbar = YES;
  73. NSString *locCity = YZMsg(@"同城");
  74. if ([cityDefault getLocationCity]) {
  75. locCity = [cityDefault getLocationCity];
  76. if ([locCity hasSuffix:@"市"]) {
  77. locCity = [locCity substringToIndex:locCity.length-1];
  78. }
  79. }
  80. NSMutableArray *arr = [NSMutableArray arrayWithArray:@[_homeVC,att,msgVC,userInfo]];
  81. for (int i = 0 ; i<arr.count; i++) {
  82. YBNavigationController *nav = [[YBNavigationController alloc]initWithRootViewController:arr[i]];
  83. [self addChildViewController:nav];
  84. }
  85. self.viewControllers = arr;
  86. Class SysTabBtn = NSClassFromString(@"UITabBarButton");
  87. for (UIView *subView in self.tabBar.subviews) {
  88. if ([subView isKindOfClass:SysTabBtn]) {
  89. subView.hidden = YES;
  90. }
  91. }
  92. [self.tabBar insertSubview:self.tabbar atIndex:3];
  93. [[UITabBar appearance]setShadowImage:[UIImage new]];
  94. [[UITabBar appearance]setBackgroundImage:[UIImage new]];
  95. }
  96. //- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
  97. // if (![[[viewController.childViewControllers firstObject] class] isEqual:[YBHomeViewController class]] &&
  98. // ![[[viewController.childViewControllers firstObject] class] isEqual:[NearbyVC class]]) {
  99. // NSLog(@"uid是%@",[Config getOwnID]);
  100. // if ([[Config getOwnID] intValue] <= 0) {
  101. // [PublicObj warnLogin];
  102. // return NO;
  103. // }else{
  104. // return YES;
  105. // }
  106. // }else{
  107. // //rk_1-30
  108. // if ([tabBarController.selectedViewController isEqual:[tabBarController.viewControllers firstObject]]) {
  109. // //! 即将选中的页面是之前上一次选中的控制器页面
  110. // if (![viewController isEqual:tabBarController.selectedViewController]) {
  111. // return YES;
  112. // }
  113. // //获取当前点击时间
  114. // NSDate *currentDate = [NSDate date];
  115. // CGFloat timeInterval = currentDate.timeIntervalSince1970 - _lastSelectedDate.timeIntervalSince1970;
  116. // // 两次点击时间间隔少于 0.5S 视为一次双击
  117. // if (timeInterval < 0.5) {
  118. // // 通知首页刷新数据
  119. // [[NSNotificationCenter defaultCenter]postNotificationName:DoubleClickRefreshNot object:nil];
  120. // // 双击之后将上次选中时间置为1970年0点0时0分0秒,用以避免连续三次或多次点击
  121. // _lastSelectedDate = [NSDate dateWithTimeIntervalSince1970:0];
  122. // return NO;
  123. // }
  124. // // 若是单击将当前点击时间复制给上一次单击时间
  125. // _lastSelectedDate = currentDate;
  126. //
  127. // }
  128. //
  129. // return YES;
  130. // }
  131. //}
  132. #pragma mark - <RTabBarDelegate>
  133. - (void)tabbar:(RTabBar *)tabbar withBtn:(TabBarType)tabbarType {
  134. // if ([[Config getOwnID] intValue]<=0 && [Config getTranslate]) {
  135. // return;
  136. // }
  137. if (tabbarType !=TabBarTypeAdd){
  138. self.selectedIndex = tabbarType-TabBarTypeHome;
  139. if(tabbarType == TabBarTypeMe || tabbarType == TabBarTypeNews){
  140. if ([[Config getOwnID] intValue] <= 0) {
  141. [PublicObj resetVC:[[YBTabBarController alloc]initWithAlert:NO]];
  142. [PublicObj warnLogin];
  143. [[NSNotificationCenter defaultCenter]postNotificationName:@"changTabBarColor" object:@"1"];
  144. return;
  145. } else{
  146. [[NSNotificationCenter defaultCenter]postNotificationName:@"changTabBarColor" object:@"1"];
  147. }
  148. }else{
  149. [[NSNotificationCenter defaultCenter]postNotificationName:@"changTabBarColor" object:@"0"];
  150. }
  151. if(tabbarType == TabBarTypeHome){
  152. //获取当前点击时间
  153. NSDate *currentDate = [NSDate date];
  154. CGFloat timeInterval = currentDate.timeIntervalSince1970 - _lastSelectedDate.timeIntervalSince1970;
  155. // 两次点击时间间隔少于 0.5S 视为一次双击
  156. if (timeInterval < 0.5) {
  157. // 通知首页刷新数据
  158. [[NSNotificationCenter defaultCenter]postNotificationName:DoubleClickRefreshNot object:nil];
  159. // 双击之后将上次选中时间置为1970年0点0时0分0秒,用以避免连续三次或多次点击
  160. _lastSelectedDate = [NSDate dateWithTimeIntervalSince1970:0];
  161. return ;
  162. }
  163. // 若是单击将当前点击时间复制给上一次单击时间
  164. _lastSelectedDate = currentDate;
  165. }
  166. return;
  167. }
  168. /// 点击了中间的相机
  169. [self centerBtnDidClicked];
  170. }
  171. #pragma mark getting
  172. - (RTabBar *)tabbar
  173. {
  174. if (!_tabbar) {
  175. _tabbar = [[RTabBar alloc] initWithFrame:CGRectMake(0, 0, _window_width, tabBarHeight)];
  176. _tabbar.delegate = self;
  177. UIApplication *app =[UIApplication sharedApplication];
  178. AppDelegate *app2 = (AppDelegate*)app.delegate;
  179. app2.rtabbar = _tabbar;
  180. }
  181. return _tabbar;
  182. }
  183. //- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
  184. // if ([[Config getOwnID] intValue]<=0 && [Config getTranslate]) {
  185. // return NO;
  186. // }
  187. //
  188. // if (![[[viewController.childViewControllers firstObject] class] isEqual:[YBHomeViewController class]] &&
  189. // ![[[viewController.childViewControllers firstObject] class] isEqual:[NearbyVC class]]) {
  190. // NSLog(@"uid是%@",[Config getOwnID]);
  191. // if ([[Config getOwnID] intValue] <= 0) {
  192. // [PublicObj warnLogin];
  193. // return NO;
  194. // }else{
  195. // return YES;
  196. // }
  197. // }else{
  198. // //rk_1-30
  199. // if ([tabBarController.selectedViewController isEqual:[tabBarController.viewControllers firstObject]]) {
  200. // //! 即将选中的页面是之前上一次选中的控制器页面
  201. // if (![viewController isEqual:tabBarController.selectedViewController]) {
  202. // return YES;
  203. // }
  204. // //获取当前点击时间
  205. // NSDate *currentDate = [NSDate date];
  206. // CGFloat timeInterval = currentDate.timeIntervalSince1970 - _lastSelectedDate.timeIntervalSince1970;
  207. // // 两次点击时间间隔少于 0.5S 视为一次双击
  208. // if (timeInterval < 0.5) {
  209. // // 通知首页刷新数据
  210. // [[NSNotificationCenter defaultCenter]postNotificationName:DoubleClickRefreshNot object:nil];
  211. // // 双击之后将上次选中时间置为1970年0点0时0分0秒,用以避免连续三次或多次点击
  212. // _lastSelectedDate = [NSDate dateWithTimeIntervalSince1970:0];
  213. // return NO;
  214. // }
  215. // // 若是单击将当前点击时间复制给上一次单击时间
  216. // _lastSelectedDate = currentDate;
  217. //
  218. // }
  219. //
  220. // return YES;
  221. // }
  222. //}
  223. /**
  224. * 中间按钮(预留)
  225. */
  226. -(void)centerBtnDidClicked {
  227. // if ([[Config getOwnID] intValue]<=0 && [Config getTranslate]) {
  228. // return;
  229. // }
  230. if ([[Config getOwnID] intValue] <= 0) {
  231. //说明是游客
  232. [PublicObj warnLogin];
  233. return;
  234. }
  235. AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
  236. if (0 < app.allUploadPro && app.allUploadPro < 1) {
  237. [MBProgressHUD showPop:YZMsg(@"视频发布中,暂不支持操作")];
  238. return;
  239. }
  240. if ([YBYoungManager shareInstance].youngSwitch == 1) {
  241. [MBProgressHUD showError:YZMsg(@"青少年模式下不支持该功能")];
  242. return;
  243. }
  244. // TCVideoPublishController *ssss = [[TCVideoPublishController alloc]init];
  245. // [[YBBaseAppDelegate sharedAppDelegate] pushViewController:ssss animated:YES];
  246. // return;
  247. BOOL mediaAccess = [[RKSysAccess shareInstance] checkMediaAccess];
  248. if (mediaAccess == NO) {
  249. YBWeakSelf;
  250. [[RKSysAccess shareInstance] requestMediaAccess:^(BOOL access) {
  251. if (access) {
  252. dispatch_async(dispatch_get_main_queue(), ^{
  253. [weakSelf requesetStatus];
  254. });
  255. }
  256. }];
  257. }else{
  258. [self requesetStatus];
  259. }
  260. }
  261. -(void)requesetStatus {
  262. YBWeakSelf;
  263. [MBProgressHUD showMessage:@""];
  264. [YBNetworking postWithUrl:@"User.checkLiveVipStatus" Dic:nil Suc:^(int code, id info, NSString *msg) {
  265. [MBProgressHUD hideHUD];
  266. if (code == 0) {
  267. //获取美狐预存值
  268. [sproutCommon getMHValueFromService];
  269. NSDictionary *dic = [info firstObject];
  270. [YBPower saveUnified:dic];
  271. [YBLiveOrVideo showLiveOrVideoSel];
  272. }else if(code == 1001){
  273. [weakSelf showAlertMsg:msg];
  274. }else{
  275. [MBProgressHUD showPop:msg];
  276. }
  277. } Fail:^(id fail) {
  278. [MBProgressHUD hideHUD];
  279. }];
  280. }
  281. -(void)showAlertMsg:(NSString *)alertMsg; {
  282. NSDictionary *contentDic = @{@"title":@"",
  283. @"msg":alertMsg,
  284. @"left":YZMsg(@"取消"),
  285. @"right":YZMsg(@"去认证")};
  286. [YBAlertView showAlertView:contentDic complete:^(int eventType) {
  287. if (eventType == 1) {
  288. dispatch_async(dispatch_get_main_queue(), ^{
  289. /*
  290. NSString *url = [NSString stringWithFormat:@"%@/Appapi/Auth/index?uid=%@&token=%@",h5url,[Config getOwnID],[Config getOwnToken]];;
  291. PubH5 *h5VC = [[PubH5 alloc]init];
  292. h5VC.url = url;
  293. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:h5VC animated:YES];
  294. */
  295. YBUserAuthVC *authVC = [[YBUserAuthVC alloc]init];
  296. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:authVC animated:YES];
  297. });
  298. }
  299. }];
  300. }
  301. /**
  302. * 初始化控制器
  303. // */
  304. //- (void)setChildViewController:(UIViewController*)childVC Title:(NSString*)title Image:(NSString *)image SelectedImage:(NSString *)selectedImage {
  305. // /**
  306. // * 添加 tabBarItem 上的文字和图片
  307. // */
  308. // childVC.tabBarItem.title=title;
  309. //// childVC.tabBarItem.image=[[UIImage imageNamed:@""]imageWithRenderingMode:UIImageRenderingModeAutomatic];;
  310. //// childVC.tabBarItem.selectedImage=[[UIImage imageNamed:@""]imageWithRenderingMode:UIImageRenderingModeAutomatic];
  311. // YBNavigationController *nav = [[YBNavigationController alloc]initWithRootViewController:childVC];
  312. //// nav.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
  313. //// nav.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -3);
  314. // [self addChildViewController:nav];
  315. //// [nav didMoveToParentViewController:self];
  316. //}
  317. ////背景色
  318. //-(UIImage *)drawTabBarItemBckgroundImageWithSize:(CGSize)size {
  319. // UIGraphicsBeginImageContext(size);
  320. // CGContextRef ctx = UIGraphicsGetCurrentContext();
  321. // CGContextSetRGBFillColor(ctx, 29.0/255, 30.0/255, 39.0/255, 1);
  322. // CGContextFillRect(ctx, CGRectMake(0, 0, size.width, size.height));
  323. // UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
  324. // UIGraphicsEndImageContext();
  325. // return img;
  326. //}
  327. //重写
  328. -(void)setNeedsStatusBarAppearanceUpdate {
  329. [super setNeedsStatusBarAppearanceUpdate];
  330. //选中背景色
  331. //CGSize indicatorImageSize = CGSizeMake(self.tabBar.bounds.size.width/4, self.tabBar.bounds.size.height);
  332. //self.tabBar.selectionIndicatorImage = [self drawTabBarItemBckgroundImageWithSize:indicatorImageSize];
  333. }
  334. - (void)selectController:(NSInteger)index{
  335. self.selectedIndex=index;
  336. _tabbar.selectIndex = index;
  337. }
  338. -(void)goForYouViewRefresh:(BOOL)refresh {
  339. [_homeVC scrollToIdx:0 refresh:refresh];
  340. }
  341. - (void)didReceiveMemoryWarning {
  342. [super didReceiveMemoryWarning];
  343. // Dispose of any resources that can be recreated.
  344. }
  345. @end