iOS 自訂滑動切換TabbarItem 覺得設計醜也要做出來的UI效果。。。

來源:互聯網
上載者:User

標籤: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效果。。。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.