【问题标题】:TabBar with NavigationController带有 NavigationController 的 TabBar
【发布时间】:2013-08-06 20:42:21
【问题描述】:

实际上,我有一个使用 NavigationController 的应用程序(带有情节提要的 Xcode 4.6.2)。我可以根据标准 NavigationController 和滑动手势提供的功能导航下一个/后退视图。

不,我正在尝试添加标签栏(最终将是自定义 UI 元素),这将允许我更改视图。例如,我想在没有滑动手势的情况下从第一个视图跳到第三个视图,但只能通过点击底部菜单上的选项卡。 我已经厌倦了添加 TabBarController(在 Xcode Editor -> Embed In -> Tab Bar Controller 中),但之后在我的所有视图导航栏上消失了。

你有什么建议我应该如何解决这个问题?

【问题讨论】:

    标签: xcode uinavigationcontroller uitabbarcontroller uitabbar navigationcontroller


    【解决方案1】:

    您可以使用 uiswipegesturerecognizer,像这样...

    - (void)viewDidLoad
    {
    [super 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];
    }
    
    - (IBAction)tappedRightButton:(id)sender
    {
          NSUInteger selectedIndex = [self.tabBarController selectedIndex];
    
    [self.tabBarController setSelectedIndex:selectedIndex + 1];
    }
    
    - (IBAction)tappedLeftButton:(id)sender
    {
    NSUInteger selectedIndex = [self.tabBarController selectedIndex];
    
    [self.tabBarController setSelectedIndex:selectedIndex - 1];
    }
    

    这很简单,它应该进入每个视图控制器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-03
      • 2017-05-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多