• UITabbarController左右滑动切换标签页


    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];

    UIView *toView = [[self.tabBarController.viewControllers objectAtIndex:selectedIndex + 1] view];

    [UIView transitionFromView:fromView toView:toView duration:0.5f options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {

    if (finished) {

    [self.tabBarController setSelectedIndex:selectedIndex + 1];

    }

    }];

    }

    }

    - (IBAction) tappedLeftButton:(id)sender

    {

    NSUInteger selectedIndex = [self.tabBarController selectedIndex];

    if (selectedIndex > 0) {

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

    UIView *toView = [[self.tabBarController.viewControllers objectAtIndex:selectedIndex - 1] view];

    [UIView transitionFromView:fromView toView:toView duration:0.5f options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {

    if (finished) {

    [self.tabBarController setSelectedIndex:selectedIndex - 1];

    }

    }];

    }


    }

  • 相关阅读:
    mac登录界面的背景壁纸图片位置
    【转载】MAC系统修改帐号短名和个人文件夹名称
    ios 6.x系统UITextView 设置为密码输入无效的问题
    一个简单的果冻弹动动画
    ios中的自动释放池
    ios 静态库联合调试
    【转】IOS制作静态库
    objective-c中为什么不能实现多重继承及如何变通实现
    回调中释放自己会不会导致崩溃?
    【转载】Objective-C runtime 消息机制
  • 原文地址:https://www.cnblogs.com/wntd/p/6640356.html
Copyright © 2020-2023  润新知