Giter Club home page Giter Club logo

wxtabbarcontroller's Introduction

WXTabBarController

GitHub license CocoaPods CocoaPods

单手操作 iPhone 6 Plus 切换 TabBar 一直是一件很痛苦的事情,而滑动切换是一种不错的解决方案,希望这种交互方式能够得到广泛地应用。

GIF

WXTabBarController

CocoaPods

你可以通过 CocoaPods 来安装 WXTabBarController

pod 'WXTabBarController', '~> 0.1'

Usage

WXTabBarController 的用法与系统 UITabBarController 的用法是完全一致的:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    
    return YES;
}

- (UINavigationController *)navigationController {
    if (_navigationController == nil) {
        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.tabBarController];
        navigationController.navigationBar.tintColor = [UIColor colorWithRed:26 / 255.0 green:178 / 255.0 blue:10 / 255.0 alpha:1];
        _navigationController = navigationController;
    }
    return _navigationController;
}

- (WXTabBarController *)tabBarController {
    if (_tabBarController == nil) {
        WXTabBarController *tabBarController = [[WXTabBarController alloc] init];
        
        ViewController *mainframeViewController = ({
            ViewController *mainframeViewController = [[ViewController alloc] init];
            
            UIImage *mainframeImage   = [UIImage imageNamed:@"tabbar_mainframe"];
            UIImage *mainframeHLImage = [UIImage imageNamed:@"tabbar_mainframeHL"];
            
            mainframeViewController.title = @"微信";
            mainframeViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"微信" image:mainframeImage selectedImage:mainframeHLImage];
            mainframeViewController.view.backgroundColor = [UIColor colorWithRed:48 / 255.0 green:67 / 255.0 blue:78 / 255.0 alpha:1];
            mainframeViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"barbuttonicon_add"]
                                                                                                         style:UIBarButtonItemStylePlain
                                                                                                        target:self
                                                                                                        action:@selector(didClickAddButton:)];
            
            mainframeViewController;
        });
        
        ViewController *contactsViewController = ({
            ViewController *contactsViewController = [[ViewController alloc] init];
            
            UIImage *contactsImage   = [UIImage imageNamed:@"tabbar_contacts"];
            UIImage *contactsHLImage = [UIImage imageNamed:@"tabbar_contactsHL"];
            
            contactsViewController.title = @"通讯录";
            contactsViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"通讯录" image:contactsImage selectedImage:contactsHLImage];
            contactsViewController.view.backgroundColor = [UIColor colorWithRed:115 / 255.0 green:155 / 255.0 blue:6 / 255.0 alpha:1];
            
            contactsViewController;
        });
        
        ViewController *discoverViewController = ({
            ViewController *discoverViewController = [[ViewController alloc] init];
            
            UIImage *discoverImage   = [UIImage imageNamed:@"tabbar_discover"];
            UIImage *discoverHLImage = [UIImage imageNamed:@"tabbar_discoverHL"];
            
            discoverViewController.title = @"发现";
            discoverViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"发现" image:discoverImage selectedImage:discoverHLImage];
            discoverViewController.view.backgroundColor = [UIColor colorWithRed:32 / 255.0 green:85 / 255.0 blue:128 / 255.0 alpha:1];
            
            discoverViewController;
        });
        
        ViewController *meViewController = ({
            ViewController *meViewController = [[ViewController alloc] init];
            
            UIImage *meImage   = [UIImage imageNamed:@"tabbar_me"];
            UIImage *meHLImage = [UIImage imageNamed:@"tabbar_meHL"];
            
            meViewController.title = @"";
            meViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:meImage selectedImage:meHLImage];
            meViewController.view.backgroundColor = [UIColor colorWithRed:199 / 255.0 green:135 / 255.0 blue:56 / 255.0 alpha:1];
            
            meViewController;
        });******
        
        tabBarController.title = @"微信";
        tabBarController.tabBar.tintColor = [UIColor colorWithRed:26 / 255.0 green:178 / 255.0 blue:10 / 255.0 alpha:1];

        tabBarController.viewControllers = @[
            [[UINavigationController alloc] initWithRootViewController:mainframeViewController],
            [[UINavigationController alloc] initWithRootViewController:contactsViewController],
            [[UINavigationController alloc] initWithRootViewController:discoverViewController],
            [[UINavigationController alloc] initWithRootViewController:meViewController],
        ];
        
        _tabBarController = tabBarController;
    }
    return _tabBarController;
}

唯一一个需要注意的地方是,整个应用是由 WXTabBarControllernavigationController 来进行导航的,而不是 Tab 页自己的 navigationController

- (void)didClickAddButton:(id)sender {
    ViewController *viewController = [[ViewController alloc] init];
    
    viewController.title = @"添加";
    viewController.view.backgroundColor = [UIColor colorWithRed:26 / 255.0 green:178 / 255.0 blue:10 / 255.0 alpha:1];
    
    [self.navigationController pushViewController:viewController animated:YES];
}

为了更直观地理解这个约定,我们一起来看一下整个应用的导航层次结构图:

WXTabBarController

Application

目前,WXTabBarController 已经在 MVVMReactiveCocoa 中正式使用,效果如下:

MVVMReactiveCocoa

Contribution

如果你有兴趣为这个库贡献代码的话,请先 Fork 这个库,然后在自己的库上做修改,最后提交 Pull request :

git clone https://github.com/your-username/WXTabBarController.git
cd WXTabBarController
pod install

License

WXTabBarController is available under the MIT license. See the LICENSE file for more info.

wxtabbarcontroller's People

Contributors

leichunfeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wxtabbarcontroller's Issues

关于present

通过AppDelegate中设置 UINavigationController作为根视图,
TabBar在根视图下。
如果实现任意界面presentViewController的话,我发现一个问题。
如:在第二个tabBar 的viewController中present [通过获取AppDelegate 的 NavigationController]一个界面的话,顶部导航栏会 出现 闪动
弹出 出现 第一个 tabBarItem 的标题, dismiss 标题又消失了

'hidesBottomBarWhenPushed' does not work

push到子视图时, 子视图中设置self.hidesBottomBarWhenPushed = YES; 属性不生效, tabBar并不消失

而且会报警告:

The unbalanced calls to begin/end appearance transitions XXX

some confuse about programming syntax

I am a little confused by your code. <br /n>
In AppDelegate.m , after line 40, some code like : <br /n>


ViewController *mainframeViewController = ({
ViewController *mainframeViewController = [[ViewController alloc] init];

    UIImage *mainframeImage   = [[UIImage imageNamed:@"tabbar_mainframe"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *mainframeHLImage = [[UIImage imageNamed:@"tabbar_mainframeHL"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    mainframeViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"微信" image:mainframeImage selectedImage:mainframeHLImage];
    mainframeViewController.view.backgroundColor = [UIColor colorWithRed:48 / 255.0 green:67 / 255.0 blue:78 / 255.0 alpha:1];

    mainframeViewController;
});

what is the last line ? I found that if I comment it mainframeViewController;(the last line in bracket) out , the compiler will complain.
I don't know what is this programming syntax. Could you offer some reference or hint, please ?

求助

你好,我想在controller加tableview,实现点击cell,push新界面,隐藏底部tab bar ??

如何滚动创建VC

目前同时创建所有tabbar对应的viewController。如何和系统的一致点击或者滑动创建tabbar对应的vc。

能否提供调用说明

你好,很棒的库,只是能否提供调用说明?新手不知道应该怎么调用,直接 pod 到库里就可以了么?还是说要调用某个 func
谢谢

您好,我有个小问题

滑动的时候navigation的title一起跟着滑动,我看代码中好像没有做特别的设置,是自动的吗?是在初始化ViewController的时候就自动生成了对应的navigationController,然后滑动的时候就跟着滑动了吗?

运行崩溃

-[_UIBadgeView font]: unrecognized selector sent to instance 0x7fcca45143d0

谢谢分享!

谢谢分享这个组件!不过我有些不同意你的说法,在iOS系统上,右滑对于cell通常是有操作的,iOS设计上也是这个倾向,你的这个组件做得很不错,只是我个人认为基本上不会被广泛的采用,在iOS上采用和Android设计理念类似的交互方式还是挺low的。纯属讨论啊。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.