详解iOS App中UiTabBarController组件的基本用法

2020-01-15 15:08:02于海丽

4> 当底部的按钮超过5个时,系统会自动增加一个more按钮,点击more后,剩余的按钮会被显示出来。

iOS,UiTabBarController

iOS,UiTabBarController

 

8.UITabbarController左右滑动切换标签页  
每个Tabbar ViewController都要添加如下代码,建议在基类中添加:

复制代码
ViewDidLoad
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tappedRightButton:)];

 

    [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];

    [self.view addGestureRecognizer:swipeLeft];

   

    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tappedLeftButton:)];

    [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];

    [self.view addGestureRecognizer:swipeRight];

 

再添加2个函数,包含切换动画效果:

复制代码
- (IBAction) tappedRightButton:(id)sender

 

{

    NSUInteger selectedIndex = [self.tabBarController selectedIndex];

   

    NSArray *aryViewController = self.tabBarController.viewControllers;

    if (selectedIndex < aryViewController.count - 1) {

        UIView *fromView = [self.tabBarController.selectedViewController view];