標籤:you xtend out dem refers first 題解 ids base
UI醜卻要繼續做的感言:
對UI不滿意的時候,就會覺得醜爆了,時間長了,卻醜習慣了。
論前一陣子Tabbar 多醜,醜得最後不要tabbar了...但是自訂tabbar 和遇到的問題解決的過程可以記錄一下
目標效果:
並有轉場效果,但是並沒說清楚,具體轉場效果,比如粘滯,彈性?
於是我做了一個彈性的。
看實現效果
一. 原理:
(1)普通切換選擇效果,直接貼在了tabbar上,tabbar再自訂處理圖層
(2)觸發事件是tabbar上的,沒有圖片而已。這麼處理也是取巧了,降低了整體自訂難度
二.遇到的問題
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UINavigationController *)viewController
代理方法裡,如何區分選中視圖控制器?
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UINavigationController *)viewController{ UIViewController *vc = viewController.viewControllers.firstObject; NSInteger tag = vc.tabBarItem.tag; NSLog(@"點擊了 第 %ld 個 tab",tag);//tag來自於視圖初始化時候的賦值}
- (UIViewController *)mineVC{ if (!_mineVC) { _mineVC = [[UIViewController alloc]init]; NSString *title = nil; _mineVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:nil selectedImage:nil]; _mineVC.tabBarItem.tag = 2;//這裡對不同的視圖的根控制器進行標記區分 _mineVC.view.backgroundColor = [UIColor redColor]; } return _mineVC;}
在應用不斷互動中,tabbar的合理顯示和隱藏?
//顯示是在主介面上的視圖控制器顯示tabbar其他情況都隱藏,處理方案:
//在視圖控制器基類HFBaseViewController裡對tabbar做顯示隱藏的邏輯判斷,並在互動過程自然顯示隱藏不突兀處理
#import <UIKit/UIKit.h>@interface HFBaseViewController : UIViewController@end//////////@interface HFBaseViewController ()@end@implementation HFBaseViewController- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor colorWithConfigKey:@"bg_white"]; if (!self.fd_prefersNavigationBarHidden) { [self setDefaultBackButtonItem]; } if (@available(iOS 11.0, *)) { [UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { self.automaticallyAdjustsScrollViewInsets = NO; } self.edgesForExtendedLayout = UIRectEdgeNone; //防止tabbar遮擋視圖}
#pragma mark - 顯示tabbar動畫- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated];if ([FIRWalletHomeVC isTypeLegal:self] || [FIRMarketVC isTypeLegal:self] || [FIRMineVC isTypeLegal:self]) { self.tabBarController.tabBar.alpha = 1.0; self.tabBarController.tabBar.hidden = NO; return ; } [UIView animateWithDuration:0.5 animations:^{ self.tabBarController.tabBar.alpha = 0.0; self.tabBarController.tabBar.hidden = YES; } completion:^(BOOL finished) { //none }];}
以上。
github 上放了源碼:clone後 直接pod update 就能運行
地址: HFCustomTabbarDemo
iOS 自訂滑動切換TabbarItem 覺得設計醜也要做出來的UI效果。。。